package cn.ainit.sys.print;

import cn.ainit.common.ReturnObject;
import cn.ainit.model.ModelReturnObj;
import cn.ainit.sys.dz.entity.SysDzSource;
import cn.ainit.sys.framework.FrameworkService;
import cn.ainit.sys.framework.entity.SysColumns;
import cn.ainit.sys.menu.MenuController;
import cn.ainit.sys.menu.SessionCont;
import cn.ainit.sys.models.ModelReceiveObj;
import cn.ainit.sys.models.SingleService;
import cn.ainit.sys.print.entity.SysPrint;
import cn.ainit.sys.query.datastore.DataStore;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/printPages")
public class PrintController {

    private PrintService printService;

    @Resource
    public void setPrintService(PrintService printService) {
        this.printService = printService;
    }

    private SingleService singleService;

    @Resource
    public void setSingleService(SingleService singleService) {
        this.singleService = singleService;
    }

    private FrameworkService frameworkService;

    @Resource
    public void setFrameworkService(FrameworkService frameworkService) {
        this.frameworkService = frameworkService;
    }


    /**
     * 加载查询条件界面字段
     *
     * @param colId
     * @param flag
     * @param type
     * @param request
     * @return
     * @throws Exception //type : 1\2 添加，详情界面
     *                   3  	查询条件界面
     *                   4 	列表结果界面
     */
    @RequestMapping("/loadColumnsU")
    @ResponseBody
    public List loadColumnsU(String dsId, String type, String flag, HttpServletRequest request, HttpSession session) throws Exception {
        Object uid = session.getAttribute(SessionCont.uid);
        if (uid == null || "".equals(uid.toString())) {
            System.out.println("用户未登录..FrameworkController L.506");
        }
        List columnsList = new ArrayList();
        try {
            String[] types = type.split(";");
            for (int i = 0; i < types.length; i++) {
                List columns = printService.loadColumnsU(dsId, types[i], flag, uid == null ? "" : uid.toString());
                columnsList.add(columns);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return columnsList;
    }


    /**
     * 通用的打印界面模板调用的controller方法
     *
     * @param dsId         datastore和column
     * @param butnId
     * @param type
     * @param staticWebUrl
     * @param initFunc
     * @param request
     * @return
     * @date : 2014-3-13 下午03:54:18
     */
    @RequestMapping("/squeryPrint")
    public String squeryPrint(ModelReceiveObj modelReceiveObj, HttpServletRequest request) throws Exception {
        try {
            ModelReturnObj modelReturnObj = new ModelReturnObj();
            //加载对照信息
            modelReturnObj.setDzObjList(loadDzInfo(modelReceiveObj.getDsId()));
            //加载主外键
            modelReturnObj.setPks(loadPks(modelReceiveObj.getDsId(), ""));
            DataStore dataStore = this.singleService.getDataStore(modelReceiveObj.getDsId());
            modelReturnObj.setDsId(modelReceiveObj.getDsId());
            modelReturnObj.setInitFunc(modelReceiveObj.getInitFunc() != null ? modelReceiveObj.getInitFunc() : "");
            modelReturnObj.setJsUrl(dataStore.getUrlJs() != null ? dataStore.getUrlJs() : "");
            modelReturnObj.setPanelTitle(dataStore.getPanelTitle());
            modelReturnObj.setPrefix(dataStore.getPrefix());
            modelReturnObj.setType(modelReceiveObj.getType());
            modelReturnObj.setKeyValues(modelReceiveObj.getKeyValues());
            request.setAttribute("m", modelReturnObj);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (modelReceiveObj.getJspWebUrl() == null || modelReceiveObj.getJspWebUrl().equals("")) {
            modelReceiveObj.setJspWebUrl("/sysPrint/basicXQPrint");
        }
        return modelReceiveObj.getJspWebUrl();
    }


    /**
     * 加载对照信息
     *
     * @param dsId
     * @return
     * @throws Exception
     */
    public List loadDzInfo(String dsId) throws Exception {
        List objAcode = new ArrayList();
        objAcode = singleService.loadDzInfo(dsId);
        return objAcode;
    }


    /**
     * 返回DG表格的主键field
     *
     * @param colId
     * @param type
     * @param request
     * @date 2014-3-14 下午04:05:01
     */
    public String loadPks(String colId, String type) throws Exception {
        StringBuffer pks = new StringBuffer("");
        try {
            List<SysColumns> columns = singleService.loadColumns(colId, type);
            for (int i = 0; (columns != null) && (i < columns.size()); i++) {
                if (columns.get(i) != null && columns.get(i).getPrimaryKey() != null && columns.get(i).getPrimaryKey().equals("T")) {
                    if (!pks.toString().equals("")) {
                        pks.append(";");
                    }
                    pks.append(columns.get(i).getName());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pks.toString();
    }


    /**
     * 当打印详情页面所访问的controller方法
     *
     * @param modelReceiveObj
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/sinfoData")
    @ResponseBody
    public ModelReturnObj sinfo(ModelReceiveObj modelReceiveObj, HttpServletRequest request, HttpSession session) throws Exception {
        ModelReturnObj modelReturnObj = new ModelReturnObj();
        List queryRow = new ArrayList();
        String[] configS = modelReceiveObj.getKeyValues().split(";");
        DataStore dataStore = this.singleService.getDataStore(modelReceiveObj.getDsId());
        //权限控制
        Object uid = session.getAttribute(SessionCont.uid);
        if (uid == null || "".equals(uid.toString())) {
            System.out.println("用户未登录 SingleController L.138");
        }
        String sql = singleService.formatSql(modelReceiveObj.getDsId(), dataStore.getSqlText(), uid == null ? "" : uid.toString());
        //权限控制结束

        if (dataStore != null) {
            StringBuffer sqlBuffer = new StringBuffer("select * from (" + sql + ") QUERYTMP where 1 = 1  ");
            String[] tmpValue;
            for (int i = 0; i < configS.length; i++) {
                tmpValue = configS[i].split("\\-");
                if (tmpValue.length == 2) {
                    sqlBuffer.append(" AND " + tmpValue[0] + "='" + tmpValue[1] + "' ");
                }
            }
            queryRow = this.singleService.queryRowBySql(sqlBuffer.toString());
        }
        modelReturnObj.setQueryRow(queryRow);
        return modelReturnObj;
    }

    @RequestMapping("/fLDataListStr")
    @ResponseBody
    public ReturnObject fLDataListStr(String str, HttpServletRequest request) throws Exception {
        ReturnObject returnObject = new ReturnObject();
        String[] objStr = str.split(",");    //分离得到每个datalist对象
        String newStr = "";
        for (int i = 0; i < objStr.length; i++) {
            String[] dataObj = objStr[i].split("-");
            String dzId = dataObj[1];     //保存对照信息的主键值
            String quCln = dataObj[0];
            String[] vals = dataObj[2].split(";");   //保存对照信息查询的条件的值
            SysDzSource sysDzSource = printService.getSysDzSource(dzId);
            String sqlStr = sysDzSource.getSqlText();    //得到该对照信息的sql语句
            String showPk = sysDzSource.getShowPk();
            String showName = sysDzSource.getShowName();
            String val = "";
            String valStr = "";
            for (int k = 0; k < vals.length; k++) {
                if (!vals[k].equals("null")) {
                    String sql = "select " + showName + " from (" + sqlStr + ") where " + showPk + "='" + vals[k] + "'";
                    val = printService.getShowNameVal(sql);
                    if (k == vals.length - 1) {
                        valStr += val;
                    } else {
                        valStr += val + ";";
                    }

                }
            }
            if (!valStr.equals("") && !valStr.equals("null")) {
                newStr += quCln + "-" + dzId + "-" + valStr + ",";
            }
        }
        returnObject.setMsg(newStr);
        return returnObject;
    }


    /**
     * 当根据模板打印时要返回的url
     *
     * @param dsId
     * @param name
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/CommonPrint")
    public String commonPrint(String pkVal, String dsId, String name, String config, String sflag, HttpServletRequest request) throws Exception {
        System.out.println(dsId + "---------" + name);
        List<Map<String, Object>> list = null;
        if (sflag.equals("s")) {
            list = printService.getPrintQueryData("select * from SYS_PRINT s  where s.DS_ID='" + dsId + "'");
        } else if (sflag.equals("m")) {
            dsId = dsId.split(";")[0];
            list = printService.getPrintQueryData("select * from SYS_PRINT s  where s.DS_ID='" + dsId + "'");
        }
        config = new String(config.getBytes("iso-8859-1"), "utf-8");
        SysPrint sysPrint = null;
        Object object = null;
        if (name == null || "".equals(name)) {
            System.out.println("正在打印单据的name 名称在Sys_Print没有注册");
            return "未找到打印模板!";
        }
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        //2. 获取打印参数
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
                System.out.println(object.toString());
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                System.out.println(dsId + "-*--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_fx_clients_jslist1".equals(dsId)) {
                    //List<Map<String,Object>> list_ = new ArrayList<Map<String,Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();
                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);
                    /* 修改：刘振涛 2015年12月21日 16:12:08
					 * 原先这里有一段代码,是获取商品信息的代码,但对账打印本身就带有相关信息,所以根本用不上,我非常确定
					 * 另外 明细数据一定要设置成 dateList ,而不是被装过的list_
					 * */
                    request.setAttribute("dataList", dateList);
                } else {
                    //如果不是对账结算单,取出主表数据放到 object 中，取出明细放到 dateList 中
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    request.setAttribute("dataList", dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
                //2.3 如果打印的是查询界面
                sysPrint = printService.getPrintObj(dsId + "_qr", name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                zSql = formatConSql(dsId, zSql, config);
                List dateList = printService.getPrintQueryData(zSql);

                request.setAttribute("dataList", dateList);
            }
            //2.4 最后将主表数据设置上
            request.setAttribute("data", object);
            //2.5 设置公司信息
            Map<String, Object> companyMap = printService.getCompanyInfo();
            request.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //2.6 通过 三元运算 取出 jsp模板路径
        System.out.println((sysPrint.getJsp() == null || "".equals(sysPrint.getJsp())) ? "sysPrint/noConf/noConf" : sysPrint.getJsp());
        return (sysPrint.getJsp() == null || "".equals(sysPrint.getJsp())) ? "sysPrint/noConf/noConf" : sysPrint.getJsp();
    }



    /***
     * 当根据模板批量打印时要返回的url
     *
     * @param dsId
     * @param name
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/CommonPrinttoPL")
    public String CommonPrinttoPL(String pkid, String pkVals, String dsId,
                                  String name, String config, String sflag, String pfks,
                                  HttpServletRequest request) throws Exception {

        name=name.substring(name.indexOf("_")+1,name.length());

        dsId = dsId.split("\\;")[0];
        String[] pkValarr = pkVals.split("\\,");
        List<Map<String, Object>> status = new ArrayList<Map<String, Object>>();
        SysPrint sysPrint = null;
        for (int i = 0; i < pkValarr.length; i++) {
            String pkVal = pkValarr[i];
            System.out.println(pkVal);
            Map<String, Object> map = new HashMap<String, Object>();
            List<Map<String, Object>> list = null;
            if (sflag.equals("s")) {
                list = printService
                        .getPrintQueryData("select * from SYS_PRINT s  where s.DS_ID='"
                                + dsId + "' and s.name = '" + name + "'");
            } else if (sflag.equals("m")) {
                dsId = dsId.split(";")[0];
                list = printService
                        .getPrintQueryData("select * from SYS_PRINT s  where s.DS_ID='"
                                + dsId + "' and s.name = '" + name + "'");
            }
            name = list.get(0).get("NAME").toString();
            config = new String(config.getBytes("iso-8859-1"), "utf-8");

            Object object = null;
            if (name == null || "".equals(name)) {
                System.out.println("正在打印单据的name 名称在Sys_Print没有注册");
                return "未找到打印模板!";
            }
            try {
                if (sflag.equals("s")) { // 只是打印单录单
                    sysPrint = printService.getPrintObj(dsId, name); // 根据用户选择的模板找到对应的模板对象
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                } else if (sflag.equals("m")) { // 打的表单是明细
                    sysPrint = printService.getPrintObj(dsId, name); // 根据用户选择的模板找到对应的模板对象
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:"
                            + zSql);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal,
                            config);
                    map.put("dataList", dateList);
                } else if (sflag.equals("l")) { // 打的查询界面
//					sysPrint = printService.getPrintObj(dsId + "_qr", name); // 根据用户选择的模板找到对应的模板对象
//					String zSql = sysPrint.getZsql();
//					zSql = formatConSql(dsId, zSql, config);
//					List dateList = printService.getPrintQueryData(zSql);
//					map.put("dataList", dateList);
                }
                request.setAttribute("data", object);
                map.put("data", object);
                Map<String, Object> companyMap = printService
                        .getCompanyInfo();
                // /
                map.put("Company", companyMap);
                status.add(map);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        request.setAttribute("status", status);
        String jspname = sysPrint.getJsp();
        sysPrint.setJsp(jspname + "3");
        return (sysPrint.getJsp() == null || "".equals(sysPrint.getJsp())) ? "sysPrint/noConf/noConf"
                : sysPrint.getJsp();
    }


    /**
     * 记录打印次数
     */
    @RequestMapping("/CommonPrintCount")
    @ResponseBody
    public String commonPrint(HttpServletRequest request,HttpSession session){
        boolean b = printService.countUpdate(request);
        return "success";
    }

    /**
     * 将前台传入的条件拼接成字符串
     *
     * @return
     * @author Xuzq
     * @date 2014-9-1 上午09:43:53
     */
    public String formatConSql(String dsId, String zSql, String config) {
        StringBuffer sqlBuffer = new StringBuffer("select * from (" + zSql + ") QUERYTMP where 1 = 1  ");
        String[] configS = null;
        config = config.replace(" ", "");
        if (config.indexOf("+") > -1) {
            configS = config.split("\\|\\+");
        } else {
            configS = config.split("\\|");
        }
        try {
            String[] tmpValue2;
            String tmpStr = "";  //缓存语句
            String tmpStr2 = ""; //缓存语句2
            String flagA = ""; //缓存标志
            String tmpName = "";//缓存 字段
            String tmpValue = "";  // 缓存值
            String editype = "";//缓存editype
            StringBuffer whereStr = new StringBuffer();//缓存条件语句
            for (int i = 0; i < configS.length; i++) {
                if (configS[i] != null && !"".equals(configS[i])) {

                    flagA = configS[i].substring(0, 1);
                    tmpStr = configS[i].substring(2, configS[i].length());
                    //					*     字符串1  ：flag - ClnName - value1 -neq +
                    //							eq  等于   		neq 	不等于
                    //					 *      alike 以...开头  	likea　	以...结尾    inc包含
                    //					 *   数值 间隔2：	 flag - date Num - value1 - value2  +
                    //					 *       列表3：     flag - staId - value1;value2 +
                    //					 	   时间间隔4:   flag - clnName- date1 - date2 +
                    if (flagA.equals("1")) {
                        tmpName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr2 = tmpStr.substring(tmpStr.lastIndexOf("-") + 1, tmpStr.length());
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.lastIndexOf("-"));
                        if ("".equals(tmpStr)) {
                            continue;
                        }
                        if ("eq".equals(tmpStr2)) {
                            sqlBuffer.append(" AND " + tmpName + "='" + tmpStr + "' ");
                        } else if ("neq".equals(tmpStr2)) {
                            sqlBuffer.append(" AND " + tmpName + " not in ('" + tmpStr + "') ");
                        } else if ("alike".equals(tmpStr2)) {
                            sqlBuffer.append(" AND " + tmpName + " like '" + tmpStr + "%' ");
                        } else if ("likea".equals(tmpStr2)) {
                            sqlBuffer.append(" AND " + tmpName + " like'%" + tmpStr + "' ");
                        } else if ("inc".equals(tmpStr2)) {
                            sqlBuffer.append(" AND " + tmpName + " like '%" + tmpStr + "%' ");
                        }
                    } else if (flagA.equals("2")) {
                        //							 *    间隔2：	   flag - clnName - Num - num2  +
                        tmpName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        if (tmpStr.lastIndexOf("-") > tmpStr.length() + 1) {
                            tmpStr2 = tmpStr.substring(tmpStr.lastIndexOf("-") + 1, tmpStr.length());
                            sqlBuffer.append(" AND " + tmpName + " <= " + tmpStr2 + " ");
                        }
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.lastIndexOf("-"));
                        if (!"".equals(tmpStr)) {
                            sqlBuffer.append(" AND " + tmpName + " >= " + tmpStr + " ");
                        }
                    } else if (flagA.equals("3")) {
                        //							flag - staId - value1;value2 +
                        tmpName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length());
                        if ("".equals(tmpStr)) {
                            continue;
                        }
                        tmpValue2 = tmpStr.split(";");
                        tmpStr = "";
                        for (int k = 0; k < tmpValue2.length; k++) {
                            tmpStr += "'" + tmpValue2[k] + "'";
                            if (k < tmpValue2.length - 1) {
                                tmpStr += ",";
                            }
                        }
                        sqlBuffer.append(" AND " + tmpName + " in (" + tmpStr + ")");
                    } else if (flagA.equals("4")) {
                        //						时间间隔4:   flag - clnName- date1 - date2 +
                        //							 input_date >  to_date('2014-5-12 00:00:00','yyyy-mm-dd hh24:mi:ss')
                        //							SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        tmpName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        String tmpStr3 = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.lastIndexOf("-"));   //第一个时间框内的值
                        String tmpStr21 = tmpStr.substring(tmpStr.lastIndexOf("-") + 1, tmpStr.length());  //第二个时间框内的值
                        if (!"".equals(tmpStr3) && !"".equals(tmpStr21) && tmpStr3.equals(tmpStr21)) {  //两个框内都有值,，并且两个值相等
                            String jqDate = df.format(new Date(Long.parseLong(tmpStr3)));
                            sqlBuffer.append(" AND to_char(" + tmpName + " ,'yyyy-MM-dd')  = '" + jqDate + "'");
                        } else {
                            if (!"".equals(tmpStr3)) {
                                sqlBuffer.append(" AND to_char(" + tmpName + ",'yyyy-MM-dd') >= '" + df.format(new Date(Long.parseLong(tmpStr3))) + "'");
                            }
                            if (!"".equals(tmpStr21)) {
                                sqlBuffer.append(" AND to_char(" + tmpName + ",'yyyy-MM-dd') <= '" + df.format(new Date(Long.parseLong(tmpStr21))) + "'");
                            }
                        }
                    } else if (flagA.equals("5")) {
                        //5 flag - ClnName - editype - value1 -neq |+
                        tmpName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr2 = tmpStr.substring(tmpStr.lastIndexOf("-") + 1, tmpStr.length());
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.lastIndexOf("-"));
                        editype = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length());

                        if ("".equals(tmpStr)) {
                            continue;
                        }
                        String ediSql = "select c.editype_add from sys_columns c where c.name='" + tmpName + "' and c.ds_id ='" + dsId + "'";
                        String ediType = frameworkService.execSqlForString(ediSql);
                        String sqlForText = "select sql_text,show_pk,show_name from sys_dz_source c where c.dz_id ='" + ediType + "'";
                        SysDzSource dzSource = (SysDzSource) frameworkService.sqlForList(sqlForText);
                        String showName = dzSource.getShowName();
                        String sqlText = dzSource.getSqlText();
                        whereStr = new StringBuffer();
                        //whereStr.append(" where 1=1 ");
                        if ("eq".equals(tmpStr2)) {
                            whereStr.append(" AND " + showName + "='" + tmpStr + "' ");
                        } else if ("neq".equals(tmpStr2)) {
                            whereStr.append(" AND " + showName + " not in ('" + tmpStr + "') ");
                        } else if ("alike".equals(tmpStr2)) {
                            whereStr.append(" AND " + showName + " like '" + tmpStr + "%' ");
                        } else if ("likea".equals(tmpStr2)) {
                            whereStr.append(" AND " + showName + " like'%" + tmpStr + "' ");
                        } else if ("inc".equals(tmpStr2)) {
                            whereStr.append(" AND " + showName + " like '%" + tmpStr + "%' ");
                        }
                        String tmpSql = " select  " + dzSource.getShowPk() + " from (" + sqlText + ") A where 1=1 " + whereStr;
                        List<Map<String, String>> idList = frameworkService.execSql(tmpSql);
                        StringBuffer likestr = new StringBuffer();
                        if (idList != null && !idList.isEmpty()) {
                            for (int j = 0; j < idList.size(); j++) {
                                likestr.append(tmpName + " like '%" + idList.get(j).get(dzSource.getShowPk()) + "%'");
                                if (j < (idList.size() - 1)) {
                                    likestr.append(" or ");
                                }
                            }
                            sqlBuffer.append(" AND (" + likestr + ") ");
                        }
                    } else if (flagA.equals("6")) {    //一对多根据ID查
                        //							flag - clnName - dsid - value1;value2 +
                        //根据dsid 和 name 查找对应的表   及对应的字段、
                        String clnName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length());
                        String dsid = tmpStr.substring(0, tmpStr.indexOf("-"));
                        //查找出包含的所有的字段
                        //只查询mul的四个字段  
                        //MULTI_CLNS_TABLE,MULTI_CLNS_FK,MULTI_CLNS_VALUE,MULTI_DZ_DS_ID
                        SysColumns tmpOnly4P = this.frameworkService.queryColumnsMul(dsid, clnName);
                        //select distinct sin_id where mul_id in (ids);
                        //								sql语句 本字段   包含在这里面

                        String[] idsArr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length()).split(";");
                        StringBuffer tmpIds = new StringBuffer();
                        for (int k = 0; k < idsArr.length; k++) {
                            tmpIds.append("'" + idsArr[k] + "'");
                            if (k < idsArr.length - 1) {
                                tmpIds.append(",");
                            }
                        }
                        //								" AND SIN_ID IN (select distinct sin_id where mul_id in (ids))
                        tmpStr = " select distinct " + tmpOnly4P.getMultiClnsFk()
                                + " from " + tmpOnly4P.getMultiClnsTable()
                                + " where " + tmpOnly4P.getMultiClnsDValue() + " in ("
                                + tmpIds + ")";
                        sqlBuffer.append(" AND " + clnName + " in (" + tmpStr + ")");
                    } else if (flagA.equals("7")) {    //一对多根据名字查
                        //							flag - clnName - dsid - value1;value2 +
                        //根据dsid 和 name 查找对应的表   及对应的字段、
                        String clnName = tmpStr.substring(0, tmpStr.indexOf("-"));
                        tmpStr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length());
                        String dsid = tmpStr.substring(0, tmpStr.indexOf("-"));
                        //查找出包含的所有的字段
                        //只查询mul的五个字段  
                        //MULTI_CLNS_TABLE,MULTI_CLNS_FK,MULTI_CLNS_VALUE,MULTI_DZ_DS_ID,EDITYPE
                        SysColumns tmpOnly4P = this.frameworkService.queryColumnsMul(dsid, clnName);
                        //select distinct sin_id where mul_id in (ids);
                        //								sql语句 本字段   包含在这里面
                        //根据对照ID查询对照的sql
                        SysDzSource dzSource = this.frameworkService.loadDzSource(tmpOnly4P.getEdiType());
                        if (dzSource == null) {
                            throw new RuntimeException("找不到对照信息[" + tmpOnly4P.getMultiDzDsId() + "]用于条件查询");
                        }
                        String[] idsArr = tmpStr.substring(tmpStr.indexOf("-") + 1, tmpStr.length()).split(";");
                        StringBuffer tmpqueryN = new StringBuffer();
                        //select multi from multiTable where multiId in ( select showID from dzsql where  name like a or like b or like c)
                        tmpqueryN.append(" select " + dzSource.getShowPk() + " from ("
                                + dzSource.getSqlText() + ") tmp where 1=1 AND ");
                        for (int k = 0; k < idsArr.length; k++) {
                            tmpqueryN.append(dzSource.getShowName() + " like '%" + idsArr[k] + "%' ");
                            if (k < idsArr.length - 1) {
                                tmpqueryN.append(" OR ");
                            }
                        }

                        //								" AND SIN_ID IN (select distinct sin_id where mul_id in (ids))
                        tmpStr = " select distinct " + tmpOnly4P.getMultiClnsFk()
                                + " from " + tmpOnly4P.getMultiClnsTable()
                                + " where " + tmpOnly4P.getMultiClnsDValue() + " in ("
                                + tmpqueryN + ")";
                        sqlBuffer.append(" AND " + clnName + " in (" + tmpStr + ")");
                    } else {
                        throw new RuntimeException("查询条件传入有误,没有按照相关规则,请联系开发调试");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sqlBuffer.toString();
    }

    /**
     * 试验销售单
     */
    @RequestMapping("jxlfords_fx_xs2")
    @ResponseBody
    public String jxlfords_fx_xs2(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson2);
        try {
            String fileName = "杭州果麦文化传媒有限公司销售出库单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //有边框
            WritableFont wtf5 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt5 = new WritableCellFormat(wtf5);
            wcfmt5.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.LEFT, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度


                wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 8, 0);

                label = new Label(0, 2, "客户名称：", wcfmt4);
                wsheet.addCell(label);

                label = new Label(1, 2, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 2, 4, 2);
                label = new Label(5, 2, "单号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 2, objjson.getString("PX_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 2, "销售日期：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 2, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 3, "主管业务员:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 3, "总包册：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, " ", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 3, 4, 3);
                label = new Label(5, 3, "总码洋：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 3, objjson.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 3, "总实洋：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 3, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 4, "收件人：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, objjson.getString("RECEIVE_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 4, "收件电话：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 4, objjson.getString("RECEIVE_TEL").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 4, 4, 4);
                label = new Label(5, 4, "总品种：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 4, objjson.getString("TOTAL_COUNT").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 4, "总数量：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 4, objjson.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);


                label = new Label(0, 5, "收件人地址：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 5, objjson.getString("RECEIVE_ADDRESS").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 5, 8, 5);

                label = new Label(0, 6, "对方单号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 6, objjson.getString("C_ZD_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 6, 8, 6);

                label = new Label(0, 7, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 7, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 7, 8, 7);

                label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                wsheet.addCell(label);
                wsheet.mergeCells(0, 9, 8, 9);

                label = new Label(0, 11, "序号");
                wsheet.addCell(label);
                label = new Label(1, 11, "书号");
                wsheet.addCell(label);
                label = new Label(2, 11, "商品名称");
				/*wsheet.addCell(label);
				label = new Label(3,11,"出版社" );*/
                wsheet.addCell(label);
                label = new Label(3, 11, "定价");
                wsheet.addCell(label);
                label = new Label(4, 11, "折扣");
                wsheet.addCell(label);
                label = new Label(5, 11, "数量");
                wsheet.addCell(label);
                label = new Label(6, 11, "码洋");
                wsheet.addCell(label);
                label = new Label(7, 11, "实洋");
                wsheet.addCell(label);
                label = new Label(8, 11, "包册数");
                wsheet.addCell(label);

                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 13 + 1, 8, overbase + 13);

                label = new Label(0, overbase + 13 + 2, "制单人：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(2, overbase + 13 + 2, "审核人：");
                wsheet.addCell(label);
                label = new Label(3, overbase + 13 + 2, objjson.getString("VERIFY_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 2, "出库人：");
                wsheet.addCell(label);
                label = new Label(5, overbase + 13 + 2, objjson.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(5, overbase + 13 + 2, 6, overbase + 13 + 2);

                label = new Label(0, overbase + 13 + 4, "户名：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(1, overbase + 13 + 4, 2, overbase + 13 + 4);
                label = new Label(3, overbase + 13 + 4, "联系人：");
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 4, 5, overbase + 13 + 4);
                label = new Label(6, overbase + 13 + 4, "邮编：");
                wsheet.addCell(label);
                label = new Label(7, overbase + 13 + 4, objjson2.getString("COM_ZIP").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(7, overbase + 13 + 4, 8, overbase + 13 + 4);

                label = new Label(0, overbase + 13 + 5, "地址：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 5, objjson2.getString("COM_ADDRESS").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(1, overbase + 13 + 5, 2, overbase + 13 + 5);
                label = new Label(3, overbase + 13 + 5, "电话：");
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 5, objjson2.getString("COM_TEL").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 5, 5, overbase + 13 + 5);
                label = new Label(6, overbase + 13 + 5, "传真：");
                wsheet.addCell(label);
                label = new Label(7, overbase + 13 + 5, objjson2.getString("COM_FAX").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(7, overbase + 13 + 5, 8, overbase + 13 + 5);

                label = new Label(0, overbase + 13 + 6, "开户行：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 6, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(1, overbase + 13 + 6, 2, overbase + 13 + 6);
                label = new Label(3, overbase + 13 + 6, "账号：");
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 6, 5, overbase + 13 + 6);
                label = new Label(6, overbase + 13 + 6, "邮箱：");
                wsheet.addCell(label);
                label = new Label(7, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(7, overbase + 13 + 6, 8, overbase + 13 + 6);

                label = new Label(0, overbase + 13 + 9, "验书：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                label = new Label(2, overbase + 13 + 9, "会计：");
                wsheet.addCell(label);
                label = new Label(3, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 9, "经手人：");
                wsheet.addCell(label);
                label = new Label(5, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                label = new Label(6, overbase + 13 + 9, "收货人：");
                wsheet.addCell(label);
                label = new Label(7, overbase + 13 + 9, " ");
                wsheet.addCell(label);

                label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 11, 8, overbase + 13 + 11);
                label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 13, 8, overbase + 13 + 13);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头
                    wsheet.setColumnView(0, 10); // 设置列的宽度
                    wsheet.setColumnView(1, 16); // 设置列的宽度
                    wsheet.setColumnView(2, 31); // 设置列的宽度
                    wsheet.setColumnView(3, 8); // 设置列的宽度
                    wsheet.setColumnView(4, 12); // 设置列的宽度
                    wsheet.setColumnView(5, 12); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 10); // 设置列的宽度
                    wsheet.setColumnView(8, 11); // 设置列的宽度


                    wsheet.setRowView(12, 0);
                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 8, 0);

                    label = new Label(0, 2, "客户名称", wcfmt5);
                    wsheet.addCell(label);

                    label = new Label(1, 2, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 2, 4, 2);
                    label = new Label(5, 2, "单号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 2, objjson.getString("PX_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 2, "销售日期：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 2, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 3, "主管业务员:", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 3, "总包册：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, " ", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 3, 4, 3);
                    label = new Label(5, 3, "总码洋：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 3, objjson.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 3, "总实洋：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 3, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 4, "收件人：", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 4, objjson.getString("RECEIVE_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 4, "收件电话：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 4, objjson.getString("RECEIVE_TEL").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 4, 4, 4);
                    label = new Label(5, 4, "总品种：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 4, objjson.getString("TOTAL_COUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 4, "总数量：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 4, objjson.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);


                    label = new Label(0, 5, "收件人地址：", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 5, objjson.getString("RECEIVE_ADDRESS").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 5, 8, 5);

                    label = new Label(0, 6, "对方单号：", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 6, objjson.getString("C_ZD_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 6, 8, 6);

                    label = new Label(0, 7, "备注：", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 7, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 7, 8, 7);

                    label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 9, 8, 9);

                    label = new Label(0, 11, "序号");
                    wsheet.addCell(label);
                    label = new Label(1, 11, "书号");
                    wsheet.addCell(label);
                    label = new Label(2, 11, "商品名称");
					/*wsheet.addCell(label);
					label = new Label(3,11,"出版社" );*/
                    wsheet.addCell(label);
                    label = new Label(3, 11, "定价");
                    wsheet.addCell(label);
                    label = new Label(4, 11, "折扣");
                    wsheet.addCell(label);
                    label = new Label(5, 11, "数量");
                    wsheet.addCell(label);
                    label = new Label(6, 11, "码洋");
                    wsheet.addCell(label);
                    label = new Label(7, 11, "实洋");
                    wsheet.addCell(label);
                    label = new Label(8, 11, "包册数");
                    wsheet.addCell(label);


                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());

                            label = new Label(0, (i + 13), (i + 1) + "");
                            wsheet.addCell(label);
                            label = new Label(1, (i + 13), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 13), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
					/*		label = new Label(3,(i+13),jsonObject.getString("PUB_NAME").replaceAll("&nbsp;", "") );
							wsheet.addCell(label);*/
                            label = new Label(3, (i + 13), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 13), jsonObject.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 13), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 13), jsonObject.getString("TOTAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(7, (i + 13), jsonObject.getString("REAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            String bcsString = "";
                            try {
                                bcsString = jsonObject.getString("PACKNUM").replaceAll("&nbsp;", "");
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                            label = new Label(8, (i + 13), bcsString);
                            wsheet.addCell(label);
                        } catch (Exception e) {
                            System.out.println(e);
                            System.out.println(i);
                        }
                    }
                    wsheet.mergeCells(0, overbase + 13 + 1, 8, overbase + 13);

                    label = new Label(0, overbase + 13 + 2, "制单人：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, overbase + 13 + 2, "审核人：");
                    wsheet.addCell(label);
                    label = new Label(3, overbase + 13 + 2, objjson.getString("VERIFY_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 2, "出库人：");
                    wsheet.addCell(label);
                    label = new Label(5, overbase + 13 + 2, objjson.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, overbase + 13 + 2, 6, overbase + 13 + 2);

                    label = new Label(0, overbase + 13 + 4, "户名：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, overbase + 13 + 4, 2, overbase + 13 + 4);
                    label = new Label(3, overbase + 13 + 4, "联系人：");
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 4, 5, overbase + 13 + 4);
                    label = new Label(6, overbase + 13 + 4, "邮编：");
                    wsheet.addCell(label);
                    label = new Label(7, overbase + 13 + 4, objjson2.getString("COM_ZIP").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, overbase + 13 + 4, 8, overbase + 13 + 4);

                    label = new Label(0, overbase + 13 + 5, "地址：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 5, objjson2.getString("COM_ADDRESS").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, overbase + 13 + 5, 2, overbase + 13 + 5);
                    label = new Label(3, overbase + 13 + 5, "电话：");
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 5, objjson2.getString("COM_TEL").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 5, 5, overbase + 13 + 5);
                    label = new Label(6, overbase + 13 + 5, "传真：");
                    wsheet.addCell(label);
                    label = new Label(7, overbase + 13 + 5, objjson2.getString("COM_FAX").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, overbase + 13 + 5, 8, overbase + 13 + 5);

                    label = new Label(0, overbase + 13 + 6, "开户行：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 6, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, overbase + 13 + 6, 2, overbase + 13 + 6);
                    label = new Label(3, overbase + 13 + 6, "账号：");
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 6, 5, overbase + 13 + 6);
                    label = new Label(6, overbase + 13 + 6, "邮箱：");
                    wsheet.addCell(label);
                    label = new Label(7, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, overbase + 13 + 6, 8, overbase + 13 + 6);

                    label = new Label(0, overbase + 13 + 9, "验书：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    label = new Label(2, overbase + 13 + 9, "会计：");
                    wsheet.addCell(label);
                    label = new Label(3, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 9, "经手人：");
                    wsheet.addCell(label);
                    label = new Label(5, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    label = new Label(6, overbase + 13 + 9, "收货人：");
                    wsheet.addCell(label);
                    label = new Label(7, overbase + 13 + 9, " ");
                    wsheet.addCell(label);

                    label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 11, 8, overbase + 13 + 11);
                    label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 13, 8, overbase + 13 + 13);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 每月实销销售单
     * *
     */
    @RequestMapping("jxlfords_cw_MonthSX1")
    @ResponseBody
    public String jxlfords_cw_MonthSX1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson2);
        try {
            String fileName = "杭州果麦文化传媒有限公司每月实销上报单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //有边框
            WritableFont wtf5 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt5 = new WritableCellFormat(wtf5);
            wcfmt5.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.LEFT, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度

                wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 12, 0);

                label = new Label(0, 2, "客户名称：", wcfmt4);
                wsheet.addCell(label);

                label = new Label(1, 2, objjson.getString("CLIENT_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 2, 4, 1);

                label = new Label(3, 2, "片区经理", wcfmt4);
                wsheet.addCell(label);

                label = new Label(4, 2, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(5, 2, "对方单号：", wcfmt4);
                wsheet.addCell(label);

                label = new Label(6, 2, objjson.getString("C_ZD_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(5, 2, "单号：", wcfmt4);
                wsheet.addCell(label);

                label = new Label(6, 2, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 3, "导入日期：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("IMPORT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(2, 3, "录单员：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(4, 3, "录单日期：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 3, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 4, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 5, 2, 1);

                label = new Label(0, 6, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                wsheet.addCell(label);
                wsheet.mergeCells(0, 6, 8, 9);

                label = new Label(0, 8, "序号");
                wsheet.addCell(label);
                label = new Label(1, 8, "书号");
                wsheet.addCell(label);
                label = new Label(2, 8, "商品名称");
                wsheet.addCell(label);
                label = new Label(3, 8, "定价");
                wsheet.addCell(label);
                label = new Label(4, 8, "销售数量");
                wsheet.addCell(label);
                label = new Label(5, 8, "销售库存");
                wsheet.addCell(label);
                label = new Label(6, 8, "导入日期");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }

                wsheet.mergeCells(0, overbase + 9 + 1, 8, overbase + 9);

                label = new Label(0, overbase + 9 + 3, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 9 + 3, 8, overbase + 9 + 3);
                label = new Label(0, overbase + 9 + 5, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 9 + 5, 8, overbase + 9 + 5);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头
                    wsheet.setColumnView(0, 10); // 设置列的宽度
                    wsheet.setColumnView(1, 16); // 设置列的宽度
                    wsheet.setColumnView(2, 31); // 设置列的宽度
                    wsheet.setColumnView(3, 8); // 设置列的宽度
                    wsheet.setColumnView(4, 12); // 设置列的宽度
                    wsheet.setColumnView(5, 12); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 10); // 设置列的宽度
                    wsheet.setColumnView(8, 11); // 设置列的宽度

                    wsheet.setRowView(12, 0);
                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 8, 0);

                    label = new Label(0, 2, "客户名称：", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(1, 2, objjson.getString("CLIENT_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 2, 4, 2);

                    label = new Label(3, 2, "片区经理", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(4, 2, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(5, 2, "对方单号：", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(6, 2, objjson.getString("C_ZD_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(8, 2, "单号：", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(9, 2, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 3, "导入日期：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("IMPORT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(5, 3, "录单员：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 3, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(8, 3, "录单日期：", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(9, 3, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 4, "备注：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 4, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 4, 2, 1);

                    label = new Label(0, 6, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 6, 8, 9);

                    label = new Label(0, 8, "序号");
                    wsheet.addCell(label);
                    label = new Label(1, 8, "书号");
                    wsheet.addCell(label);
                    label = new Label(2, 8, "商品名称");
                    wsheet.addCell(label);
                    label = new Label(3, 8, "定价");
                    wsheet.addCell(label);
                    label = new Label(4, 8, "销售数量");
                    wsheet.addCell(label);
                    label = new Label(5, 8, "销售库存");
                    wsheet.addCell(label);
                    label = new Label(6, 8, "导入日期");
                    wsheet.addCell(label);


                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {
                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());

                            label = new Label(0, (i + 9), (i + 1) + "");
                            wsheet.addCell(label);
                            label = new Label(1, (i + 9), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 9), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 9), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 9), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 9), jsonObject.getString("AMOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);


                            label = new Label(6, (i + 9), jsonObject.getString("IMPORT_DATEM").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            String bcsString = "";
                            try {
                                bcsString = jsonObject.getString("PACKNUM").replaceAll("&nbsp;", "");
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                            label = new Label(8, (i + 9), bcsString);
                            wsheet.addCell(label);
                        } catch (Exception e) {
                            System.out.println(e);
                            System.out.println(i);
                        }
                    }
                    wsheet.mergeCells(0, overbase + 9 + 1, 8, overbase + 9);

                    label = new Label(0, overbase + 9 + 3, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9 + 3, 8, overbase + 9 + 3);
                    label = new Label(0, overbase + 9 + 5, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9 + 5, 8, overbase + 9 + 5);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 纸厂对账
     * <p/>
     * jxlfords_cw_clreconcid1
     * ds_cw_clreconcid1
     */
    @RequestMapping("jxlfords_cw_clreconcid1")
    @ResponseBody
    public String jxlfords_cw_clreconcid1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_cw_clreconcid1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);
                    list2 = dateList;

                    String VENDOR_ID = JSONObject.fromObject(object).getString("VENDOR_ID").replaceAll("&nbsp;", "");
                    String MMSQL = "SELECT (TO_CHAR(VV.IS_STOKETIME, 'yyyy-mm-dd')) IS_STOKETIME, VV.DJ_CODE, (select STATUS_NAME from (SELECT 'IN' STATUS_ID, '纸张入库单' STATUS_NAME from dual UNION ALL SELECT 'TH' STATUS_ID, '纸张退货单' STATUS_NAME from dual UNION ALL SELECT 'RK' STATUS_ID, '纸张其他入库单' STATUS_NAME from dual) aa where aa.STATUS_ID = VV.DJ_TYPE) DJ_TYPE, VV.CL_HETONGHAO, (select b.cl_name from bs_material b where b.cl_id = VV.CL_ID) CL_NAME, VV.CL_STANDARD, VV.CL_PRICE, (select name from bs_comparison where comparison_id = 'cljlUnit' and codeId = VV.CL_UNIT) CL_UNIT, VV.TOTAL_AMOUNT, VV.REAL_MONEY, VV.TAX_RATE, VV.TAX_MONEY, VV.MX_BHMONEYSUM FROM VV_CW_ZCDZ VV left join bs_man on bs_man.man_id=vv.VENDOR_ID WHERE VV.I_INFO NOT IN (SELECT CMI.I_INFO FROM cw_clreconcid_item CMI LEFT JOIN CW_CLRECONCID CM ON CMI.CL_ID = CM.CL_ID WHERE cm.is_destroy = '0') AND bs_man.m_name='" + VENDOR_ID + "'";
                    list3 = printService.getPrintMMList(MMSQL);

                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //2.4 最后将主表数据设置上

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
//		

        try {
//			String fileName=objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "")+"纸厂对账";
            String fileName = "纸厂对账";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);


            //大循环

            int t = 0;

            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
            //设置表头

            Label label = new Label(0, 0, fileName);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "纸厂编码：");
            wsheet.addCell(label);
            label = new Label(2, 1, objjson.getString("VENDOR_ID").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(2, 1, 7, 1);

//			label = new Label(0,2,"客户名称:" );
//			wsheet.addCell(label);
//			label = new Label(1,2,objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(1, 2, 2, 2);
            label = new Label(0, 2, "打印日期：");
            wsheet.addCell(label);
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String daString = "";
            daString = simpleDateFormat.format(date);
            label = new Label(2, 2, daString);
            wsheet.addCell(label);
//			label = new Label(5,2,"结算日期：" );
//			wsheet.addCell(label);
//			label = new Label(6,2,objjson.getString("JS_MONTH").replaceAll("&nbsp;", "") );
//			wsheet.addCell(label);
//			wsheet.mergeCells(0,3,7,3);
//
            label = new Label(0, 4, "账期内：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 4, 7, 4);
            wsheet.mergeCells(0, 5, 7, 5);

            label = new Label(0, 6, "序号");
            wsheet.addCell(label);
            label = new Label(1, 6, "出库日期");
            wsheet.addCell(label);
            label = new Label(2, 6, "单据号");
            wsheet.addCell(label);
            label = new Label(3, 6, "单据类型");
            wsheet.addCell(label);
            label = new Label(4, 6, "合同号");
            wsheet.addCell(label);
            label = new Label(5, 6, "材料名称");
            wsheet.addCell(label);
            label = new Label(6, 6, "规格");
            wsheet.addCell(label);
            label = new Label(7, 6, "单价");
            wsheet.addCell(label);
            label = new Label(8, 6, "单位");
            wsheet.addCell(label);
            label = new Label(9, 6, "合同数量");
            wsheet.addCell(label);
            label = new Label(10, 6, "应付金额");
            wsheet.addCell(label);
            label = new Label(11, 6, "税率");
            wsheet.addCell(label);
            label = new Label(12, 6, "税金");
            wsheet.addCell(label);
            label = new Label(13, 6, "不含税金额");
            wsheet.addCell(label);
            //明细（账期内）
            if (list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(list2.get(i));
                    label = new Label(0, 7 + i, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 7 + i, objjsonzn.getString("IS_STOKETIME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 7 + i, objjsonzn.getString("DJ_CODE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 7 + i, objjsonzn.getString("DJ_TYPE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 7 + i, objjsonzn.getString("CL_HETONGHAO").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 7 + i, objjsonzn.getString("CL_NAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(6, 7 + i, objjsonzn.getString("CL_STANDARD").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(7, 7 + i, objjsonzn.getString("CL_PRICE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(8, 7 + i, objjsonzn.getString("CL_UNIT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(9, 7 + i, objjsonzn.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(10, 7 + i, objjsonzn.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(11, 7 + i, objjsonzn.getString("TAX_RATE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(12, 7 + i, objjsonzn.getString("TAX_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(13, 7 + i, objjsonzn.getString("MX_BHMONEYSUM").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                }
            }
            label = new Label(0, 7 + list2.size() + 1, "本期应收款：" + objjson.getString("ZONG_REAL_MONEY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 1, 7, 7 + list2.size() + 1);
            wsheet.mergeCells(0, 7 + list2.size() + 2, 7, 7 + list2.size() + 2);

            label = new Label(0, 7 + list2.size() + 3, "账期外：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 3, 7, 7 + list2.size() + 3);
            wsheet.mergeCells(0, 7 + list2.size() + 4, 7, 7 + list2.size() + 4);

            label = new Label(0, 7 + list2.size() + 5, "序号");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 5, "出库日期");
            wsheet.addCell(label);
            label = new Label(2, 7 + list2.size() + 5, "单据号");
            wsheet.addCell(label);
            label = new Label(3, 7 + list2.size() + 5, "单据类型");
            wsheet.addCell(label);
            label = new Label(4, 7 + list2.size() + 5, "合同号");
            wsheet.addCell(label);
            label = new Label(5, 7 + list2.size() + 5, "材料名称");
            wsheet.addCell(label);
            label = new Label(6, 7 + list2.size() + 5, "规格");
            wsheet.addCell(label);
            label = new Label(7, 7 + list2.size() + 5, "单价");
            wsheet.addCell(label);
            label = new Label(8, 7 + list2.size() + 5, "单位");
            wsheet.addCell(label);
            label = new Label(9, 7 + list2.size() + 5, "合同数量");
            wsheet.addCell(label);
            label = new Label(10, 7 + list2.size() + 5, "应付金额");
            wsheet.addCell(label);
            label = new Label(11, 7 + list2.size() + 5, "税率");
            wsheet.addCell(label);
            label = new Label(12, 7 + list2.size() + 5, "税金");
            wsheet.addCell(label);
            label = new Label(13, 7 + list2.size() + 5, "不含税金额");
            wsheet.addCell(label);
//			label = new Label(6,7+datazn.size()+5,"备注" );
//			wsheet.addCell(label);
//			wsheet.mergeCells(6,7+datazn.size()+5,7,7+datazn.size()+5);

            //for  
            if (list3.size() > 0) {
                for (int i = 0; i < list3.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(list3.get(i));
                    label = new Label(0, 7 + list2.size() + 5 + i + 1, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("IS_STOKETIME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("DJ_CODE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("DJ_TYPE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("CL_HETONGHAO").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("CL_NAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(6, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("CL_STANDARD").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(7, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("CL_PRICE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(8, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("CL_UNIT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(9, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(10, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(11, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("TAX_RATE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(12, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("TAX_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(13, 7 + list2.size() + 5 + i + 1, objjsonzn.getString("MX_BHMONEYSUM").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                }
            }
            label = new Label(0, 7 + list2.size() + 5 + list3.size() + 1, "账期外应收款：" + objjson.getString("ZQWMONEY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 5 + list3.size() + 1, 7, 7 + list2.size() + 5 + list3.size() + 1);
            wsheet.mergeCells(0, 7 + list2.size() + 5 + list3.size() + 2, 7, 7 + list2.size() + 5 + list3.size() + 2);

//			label = new Label(0,7+datazn.size()+5+datazw.size()+3,"业务联系方式");
//			wsheet.addCell(label);
//			wsheet.mergeCells(0, 7+datazn.size()+5+datazw.size()+3,7, 7+datazn.size()+5+datazw.size()+3);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+4,"电话：");
//			wsheet.addCell(label);
//			label = new Label(1,7+datazn.size()+5+datazw.size()+4,objjson.getString("O_TELPHONE").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(1, 7+datazn.size()+5+datazw.size()+4,2, 7+datazn.size()+5+datazw.size()+4);
//			label = new Label(3,7+datazn.size()+5+datazw.size()+4,"联系人：");
//			wsheet.addCell(label);
//			label = new Label(4,7+datazn.size()+5+datazw.size()+4,objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(4, 7+datazn.size()+5+datazw.size()+4,5, 7+datazn.size()+5+datazw.size()+4);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+5,"传真：");
//			wsheet.addCell(label);
//			label = new Label(1,7+datazn.size()+5+datazw.size()+5,objjson.getString("C_FAX").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(1, 7+datazn.size()+5+datazw.size()+5,2, 7+datazn.size()+5+datazw.size()+5);
//			label = new Label(3,7+datazn.size()+5+datazw.size()+5,"对账：");
//			wsheet.addCell(label);
//			label = new Label(4,7+datazn.size()+5+datazw.size()+5,objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(4, 7+datazn.size()+5+datazw.size()+5,5, 7+datazn.size()+5+datazw.size()+5);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+6,"财务资料");
//			wsheet.addCell(label);
//			wsheet.mergeCells(0, 7+datazn.size()+5+datazw.size()+6,7, 7+datazn.size()+5+datazw.size()+6);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+7,"户名：");
//			wsheet.addCell(label);
//			label = new Label(1,7+datazn.size()+5+datazw.size()+7,objjson2.getString("ACCOUNT_NAME1").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(1, 7+datazn.size()+5+datazw.size()+7,7, 7+datazn.size()+5+datazw.size()+7);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+8,"开户行：");
//			wsheet.addCell(label);
//			label = new Label(1,7+datazn.size()+5+datazw.size()+8,objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(1, 7+datazn.size()+5+datazw.size()+8,2, 7+datazn.size()+5+datazw.size()+8);
//			label = new Label(3,7+datazn.size()+5+datazw.size()+8,"账号：");
//			wsheet.addCell(label);
//			label = new Label(4,7+datazn.size()+5+datazw.size()+8,objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(4, 7+datazn.size()+5+datazw.size()+8,5, 7+datazn.size()+5+datazw.size()+8);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+9,"退货地址：");
//			wsheet.addCell(label);
//			wsheet.mergeCells(0, 7+datazn.size()+5+datazw.size()+9,7, 7+datazn.size()+5+datazw.size()+9);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+10,"地址：");
//			wsheet.addCell(label);
//			label = new Label(1,7+datazn.size()+5+datazw.size()+10,objjson2.getString("STOCK_ADDRESS").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			label = new Label(2,7+datazn.size()+5+datazw.size()+10,"电话：");
//			wsheet.addCell(label);
//			label = new Label(3,7+datazn.size()+5+datazw.size()+10,objjson2.getString("STOCK_TEL").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(3, 7+datazn.size()+5+datazw.size()+10,4, 7+datazn.size()+5+datazw.size()+10);
//			label = new Label(5,7+datazn.size()+5+datazw.size()+10,"邮编：");
//			wsheet.addCell(label);
//			label = new Label(6,7+datazn.size()+5+datazw.size()+10,objjson2.getString("STOCK_ZIP").replaceAll("&nbsp;", ""));
//			wsheet.addCell(label);
//			wsheet.mergeCells(6, 7+datazn.size()+5+datazw.size()+10,7, 7+datazn.size()+5+datazw.size()+10);
//
//			label = new Label(0,7+datazn.size()+5+datazw.size()+11,"对账信息(请盖章并回传)");
//			wsheet.addCell(label);
//			wsheet.mergeCells(0, 7+datazn.size()+5+datazw.size()+11,7, 7+datazn.size()+5+datazw.size()+11);

            label = new Label(0, 7 + list2.size() + 5 + list3.size() + 12, "技术支持:上海爱你特科技www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 5 + list3.size() + 12, 7, 7 + list2.size() + 5 + list3.size() + 12);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 结算清单ds_fx_clients_jslist1 b
     */
    @RequestMapping("jxlfords_fx_clients_jslist1")
    @ResponseBody
    public String jxlfords_fx_clients_jslist1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_fx_clients_jslist1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);

                    for (int i = 0, size = dateList.size(); i < size; i++) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        String YW_CODE = dateList.get(i).get("YW_CODE").toString();
                        String MMSQL = "select bs_product.h_isbn,bs_product.h_name,fx_xs_item.h_amount,fx_xs_item.h_price,fx_xs_item.h_discount,fx_xs_item.total_money_item,fx_xs_item.real_money_item  from fx_xs, fx_xs_item ,bs_product where fx_xs.px_id = fx_xs_item.px_id and fx_xs_item.h_id = bs_product.h_id and fx_xs.px_code = '" + YW_CODE + "'";
                        List<Map<String, Object>> dateList_ = printService.getPrintMMList(MMSQL);
                        map.put("data", dateList.get(i));
                        map.put("dataItem", dateList_);
                        list_.add(map);
                    }
                    list2 = list_;


                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //2.4 最后将主表数据设置上

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        List datazn = new ArrayList();
        List datazw = new ArrayList();
        System.out.println(objjson.toString());
        for (int i = 0; i < list2.size(); i++) {
            JSONObject objjson3 = JSONObject.fromObject(list2.get(i));
            JSONObject objjson4 = JSONObject.fromObject(objjson3.getString("data"));
            if ("ZN".equals(objjson4.getString("D_TYPE").replaceAll("&nbsp;", ""))) {
                datazn.add(list2.get(i));
            } else if ("ZW".equals(objjson4.getString("D_TYPE").replaceAll("&nbsp;", ""))) {
                datazw.add(list2.get(i));
            }

        }

        try {
            String fileName = objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "") + "对账结算单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);


            //大循环

            int t = 0;

            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
            //设置表头

            Label label = new Label(0, 0, fileName);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "客户编码：");
            wsheet.addCell(label);
            label = new Label(2, 1, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(2, 1, 7, 1);

            label = new Label(0, 2, "客户名称:");
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 2, 2);
            label = new Label(3, 2, "打印日期：");
            wsheet.addCell(label);
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String daString = "";
            daString = simpleDateFormat.format(date);
            label = new Label(4, 2, daString);
            wsheet.addCell(label);
            label = new Label(5, 2, "结算日期：");
            wsheet.addCell(label);
            label = new Label(6, 2, objjson.getString("JS_MONTH").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 3, 7, 3);

            label = new Label(0, 4, "账期内：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 4, 7, 4);
            wsheet.mergeCells(0, 5, 7, 5);

            label = new Label(0, 6, "序号");
            wsheet.addCell(label);
            label = new Label(1, 6, "录入日期");
            wsheet.addCell(label);
            label = new Label(2, 6, "凭证单号");
            wsheet.addCell(label);
            label = new Label(3, 6, "码洋");
            wsheet.addCell(label);
            label = new Label(4, 6, "折扣");
            wsheet.addCell(label);
            label = new Label(5, 6, "实洋");
            wsheet.addCell(label);
            label = new Label(6, 6, "备注");
            wsheet.addCell(label);
            wsheet.mergeCells(6, 6, 7, 6);

            //for 
            if (datazn.size() > 0) {
                for (int i = 0; i < datazn.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(datazn.get(i));
                    objjsonzn = JSONObject.fromObject(objjsonzn.getString("data"));
                    label = new Label(0, 7 + i, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 7 + i, objjsonzn.getString("YW_INPUT_DATE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 7 + i, objjsonzn.getString("YW_CODE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 7 + i, objjsonzn.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 7 + i, objjsonzn.getString("C_DISCOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 7 + i, objjsonzn.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    String memoString = objjsonzn.getString("YW_MEMO").replaceAll("&nbsp;", "");
                    if (memoString == null || "".equals(memoString) || "null".equals(memoString)) {
                        memoString = "";
                    }
                    label = new Label(6, 7 + i, memoString);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 7 + i, 7, 7 + i);
                }
            }
            label = new Label(0, 7 + datazn.size() + 1, "本期应收款：" + objjson.getString("THIS_YS_MONEY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 1, 7, 7 + datazn.size() + 1);
            wsheet.mergeCells(0, 7 + datazn.size() + 2, 7, 7 + datazn.size() + 2);
            label = new Label(0, 7 + datazn.size() + 3, "账期外：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 3, 7, 7 + datazn.size() + 3);
            wsheet.mergeCells(0, 7 + datazn.size() + 4, 7, 7 + datazn.size() + 4);

            label = new Label(0, 7 + datazn.size() + 5, "序号");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5, "录入日期");
            wsheet.addCell(label);
            label = new Label(2, 7 + datazn.size() + 5, "凭证单号");
            wsheet.addCell(label);
            label = new Label(3, 7 + datazn.size() + 5, "码洋");
            wsheet.addCell(label);
            label = new Label(4, 7 + datazn.size() + 5, "折扣");
            wsheet.addCell(label);
            label = new Label(5, 7 + datazn.size() + 5, "实洋");
            wsheet.addCell(label);
            label = new Label(6, 7 + datazn.size() + 5, "备注");
            wsheet.addCell(label);
            wsheet.mergeCells(6, 7 + datazn.size() + 5, 7, 7 + datazn.size() + 5);

            //for  
            if (datazw.size() > 0) {
                for (int i = 0; i < datazw.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(datazw.get(i));
                    objjsonzn = JSONObject.fromObject(objjsonzn.getString("data"));
                    label = new Label(0, 7 + datazn.size() + 5 + i + 1, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 7 + datazn.size() + 5 + i + 1, objjsonzn.getString("YW_INPUT_DATE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 7 + datazn.size() + 5 + i + 1, objjsonzn.getString("YW_CODE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 7 + datazn.size() + 5 + i + 1, objjsonzn.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 7 + datazn.size() + 5 + i + 1, objjsonzn.getString("C_DISCOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 7 + datazn.size() + 5 + i + 1, objjsonzn.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    String memoString = objjsonzn.getString("YW_MEMO").replaceAll("&nbsp;", "");
                    if (memoString == null || "".equals(memoString) || "null".equals(memoString)) {
                        memoString = "";
                    }
                    label = new Label(6, 7 + datazn.size() + 5 + i + 1, memoString);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 7 + datazn.size() + 5 + i + 1, 7, 7 + datazn.size() + 5 + i + 1);
                }
            }
            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 1, "总欠款：" + objjson.getString("THIS_ZYS").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 1, 7, 7 + datazn.size() + 5 + datazw.size() + 1);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 2, 7, 7 + datazn.size() + 5 + datazw.size() + 2);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 3, "业务联系方式");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 3, 7, 7 + datazn.size() + 5 + datazw.size() + 3);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 4, "电话：");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5 + datazw.size() + 4, objjson.getString("O_TELPHONE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + datazn.size() + 5 + datazw.size() + 4, 2, 7 + datazn.size() + 5 + datazw.size() + 4);
            label = new Label(3, 7 + datazn.size() + 5 + datazw.size() + 4, "联系人：");
            wsheet.addCell(label);
            label = new Label(4, 7 + datazn.size() + 5 + datazw.size() + 4, objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + datazn.size() + 5 + datazw.size() + 4, 5, 7 + datazn.size() + 5 + datazw.size() + 4);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 5, "传真：");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5 + datazw.size() + 5, objjson.getString("C_FAX").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + datazn.size() + 5 + datazw.size() + 5, 2, 7 + datazn.size() + 5 + datazw.size() + 5);
            label = new Label(3, 7 + datazn.size() + 5 + datazw.size() + 5, "对账：");
            wsheet.addCell(label);
            label = new Label(4, 7 + datazn.size() + 5 + datazw.size() + 5, objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + datazn.size() + 5 + datazw.size() + 5, 5, 7 + datazn.size() + 5 + datazw.size() + 5);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 6, "财务资料");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 6, 7, 7 + datazn.size() + 5 + datazw.size() + 6);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 7, "户名：");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5 + datazw.size() + 7, objjson2.getString("ACCOUNT_NAME1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + datazn.size() + 5 + datazw.size() + 7, 7, 7 + datazn.size() + 5 + datazw.size() + 7);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 8, "开户行：");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5 + datazw.size() + 8, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + datazn.size() + 5 + datazw.size() + 8, 2, 7 + datazn.size() + 5 + datazw.size() + 8);
            label = new Label(3, 7 + datazn.size() + 5 + datazw.size() + 8, "账号：");
            wsheet.addCell(label);
            label = new Label(4, 7 + datazn.size() + 5 + datazw.size() + 8, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + datazn.size() + 5 + datazw.size() + 8, 5, 7 + datazn.size() + 5 + datazw.size() + 8);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 9, "退货地址：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 9, 7, 7 + datazn.size() + 5 + datazw.size() + 9);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 10, "地址：");
            wsheet.addCell(label);
            label = new Label(1, 7 + datazn.size() + 5 + datazw.size() + 10, objjson2.getString("STOCK_ADDRESS").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            label = new Label(2, 7 + datazn.size() + 5 + datazw.size() + 10, "电话：");
            wsheet.addCell(label);
            label = new Label(3, 7 + datazn.size() + 5 + datazw.size() + 10, objjson2.getString("STOCK_TEL").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(3, 7 + datazn.size() + 5 + datazw.size() + 10, 4, 7 + datazn.size() + 5 + datazw.size() + 10);
            label = new Label(5, 7 + datazn.size() + 5 + datazw.size() + 10, "邮编：");
            wsheet.addCell(label);
            label = new Label(6, 7 + datazn.size() + 5 + datazw.size() + 10, objjson2.getString("STOCK_ZIP").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 7 + datazn.size() + 5 + datazw.size() + 10, 7, 7 + datazn.size() + 5 + datazw.size() + 10);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 11, "对账信息(请盖章并回传)");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 11, 7, 7 + datazn.size() + 5 + datazw.size() + 11);

            label = new Label(0, 7 + datazn.size() + 5 + datazw.size() + 12, "技术支持:上海爱你特科技www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + datazn.size() + 5 + datazw.size() + 12, 7, 7 + datazn.size() + 5 + datazw.size() + 12);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 结算清单ds_fx_clients_jslist1tofzq
     */
    @RequestMapping("jxlfords_fx_clients_jslist1tofzq")
    @ResponseBody
    public String jxlfords_fx_clients_jslist1tofzq(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_fx_clients_jslist1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);

                    for (int i = 0, size = dateList.size(); i < size; i++) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        String YW_CODE = dateList.get(i).get("YW_CODE").toString();
                        String MMSQL = "select bs_product.h_isbn,bs_product.h_name,fx_xs_item.h_amount,fx_xs_item.h_price,fx_xs_item.h_discount,fx_xs_item.total_money_item,fx_xs_item.real_money_item  from fx_xs, fx_xs_item ,bs_product where fx_xs.px_id = fx_xs_item.px_id and fx_xs_item.h_id = bs_product.h_id and fx_xs.px_code = '" + YW_CODE + "'";
                        List<Map<String, Object>> dateList_ = printService.getPrintMMList(MMSQL);
                        map.put("data", dateList.get(i));
                        map.put("dataItem", dateList_);
                        list_.add(map);
                    }
                    list2 = list_;


                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //2.4 最后将主表数据设置上

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        try {
            String fileName = objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "") + "对账结算单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);


            //大循环

            int t = 0;

            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
            //设置表头

            Label label = new Label(0, 0, fileName);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "客户编码：");
            wsheet.addCell(label);
            label = new Label(2, 1, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(2, 1, 7, 1);

            label = new Label(0, 2, "客户名称:");
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 2, 2);
            label = new Label(3, 2, "打印日期：");
            wsheet.addCell(label);
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String daString = "";
            daString = simpleDateFormat.format(date);
            label = new Label(4, 2, daString);
            wsheet.addCell(label);
            label = new Label(5, 2, "结算日期：");
            wsheet.addCell(label);
            label = new Label(6, 2, objjson.getString("JS_MONTH").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 3, 7, 3);

            label = new Label(0, 6, "序号");
            wsheet.addCell(label);
            label = new Label(1, 6, "录入日期");
            wsheet.addCell(label);
            label = new Label(2, 6, "凭证单号");
            wsheet.addCell(label);
            label = new Label(3, 6, "码洋");
            wsheet.addCell(label);
            label = new Label(4, 6, "折扣");
            wsheet.addCell(label);
            label = new Label(5, 6, "实洋");
            wsheet.addCell(label);
            label = new Label(6, 6, "备注");
            wsheet.addCell(label);
            wsheet.mergeCells(6, 6, 7, 6);

            //for 

            for (int i = 0; i < list2.size(); i++) {
                JSONObject objjsonzn = JSONObject.fromObject(list2.get(i));
                objjsonzn = JSONObject.fromObject(objjsonzn.getString("data"));
                label = new Label(0, 7 + i, (i + 1) + "");
                wsheet.addCell(label);
                label = new Label(1, 7 + i, objjsonzn.getString("YW_INPUT_DATE").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(2, 7 + i, objjsonzn.getString("YW_CODE").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(3, 7 + i, objjsonzn.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(4, 7 + i, objjsonzn.getString("C_DISCOUNT").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(5, 7 + i, objjsonzn.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                String memoString = objjsonzn.getString("YW_MEMO").replaceAll("&nbsp;", "");
                if (memoString == null || "".equals(memoString) || "null".equals(memoString)) {
                    memoString = "";
                }
                label = new Label(6, 7 + i, memoString);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 7 + i, 7, 7 + i);
            }

            label = new Label(0, 7 + list2.size() + 2, "总欠款：" + objjson.getString("THIS_ZYS").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 2, 7, 7 + list2.size() + 2);
            wsheet.mergeCells(0, 7 + list2.size() + 3, 7, 7 + list2.size() + 3);

            label = new Label(0, 7 + list2.size() + 4, "业务联系方式");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + 7 + list2.size() + 4, 7, 7 + list2.size() + 4);

            label = new Label(0, 7 + list2.size() + 5, "电话：");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 5, objjson.getString("O_TELPHONE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + list2.size() + 5, 2, 7 + list2.size() + 5);
            label = new Label(3, 7 + list2.size() + 5, "联系人：");
            wsheet.addCell(label);
            label = new Label(4, 7 + list2.size() + 5, objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + list2.size() + 5, 5, 7 + list2.size() + 5);

            label = new Label(0, 7 + list2.size() + 6, "传真：");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 6, objjson.getString("C_FAX").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + list2.size() + 6, 2, 7 + list2.size() + 6);
            label = new Label(3, 7 + list2.size() + 6, "对账：");
            wsheet.addCell(label);
            label = new Label(4, 7 + list2.size() + 6, objjson.getString("O_NAME").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + list2.size() + 6, 5, 7 + list2.size() + 6);

            label = new Label(0, 7 + list2.size() + 7, "财务资料");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 7, 7, 7 + list2.size() + 7);

            label = new Label(0, 7 + list2.size() + 8, "户名：");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 8, objjson2.getString("ACCOUNT_NAME1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + list2.size() + 8, 7, 7 + list2.size() + 8);

            label = new Label(0, 7 + list2.size() + 9, "开户行：");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 9, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 7 + list2.size() + 9, 2, 7 + list2.size() + 9);
            label = new Label(3, 7 + list2.size() + 9, "账号：");
            wsheet.addCell(label);
            label = new Label(4, 7 + list2.size() + 9, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(4, 7 + list2.size() + 9, 5, 7 + list2.size() + 9);

            label = new Label(0, 7 + list2.size() + 10, "退货地址：");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 10, 7, 7 + list2.size() + 10);

            label = new Label(0, 7 + list2.size() + 11, "地址：");
            wsheet.addCell(label);
            label = new Label(1, 7 + list2.size() + 11, objjson2.getString("STOCK_ADDRESS").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            label = new Label(2, 7 + list2.size() + 11, "电话：");
            wsheet.addCell(label);
            label = new Label(3, 7 + list2.size() + 11, objjson2.getString("STOCK_TEL").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(3, 7 + list2.size() + 11, 4, 7 + list2.size() + 11);
            label = new Label(5, 7 + list2.size() + 11, "邮编：");
            wsheet.addCell(label);
            label = new Label(6, 7 + list2.size() + 11, objjson2.getString("STOCK_ZIP").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 7 + list2.size() + 11, 7, 7 + list2.size() + 11);

            label = new Label(0, 7 + list2.size() + 12, "对账信息(请盖章并回传)");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 12, 7, 7 + list2.size() + 12);

            label = new Label(0, 7 + list2.size() + 14, "技术支持:上海爱你特科技www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 7 + list2.size() + 14, 7, 7 + list2.size() + 14);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 试验销售单收款核销
     */
    @RequestMapping("jxlfords_fx_charge1")
    @ResponseBody
    public String jxlfords_fx_charge1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //					req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);

        try {
            String fileName = "杭州果麦文化传媒有限公司收款单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);
            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //表格样式

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);

                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度

                //设置表头
                Label label = new Label(0, 0, "杭州果麦文化传媒有限公司收款单", wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 7, 0);

                label = new Label(0, 1, "客户名称", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 1, 1, 1);
                label = new Label(2, 1, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 1, 3, 1);
                label = new Label(4, 1, "收款单号", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 1, 5, 1);
                label = new Label(6, 1, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 1, 7, 1);

                label = new Label(0, 2, "客户编号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("CLIENT_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 2, "部门编号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 2, "收款方式:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 2, objjson.getString("SK_CLASS").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 3, "录单日期:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 3, "收款人：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 3, "凭证编号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 3, objjson.getString("PZ_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 4, "站点编号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, objjson.getString("STATION_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 4, "支票汇票：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 4, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 4, "收款金额:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 4, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 5, "收款大写", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 5, 1, 5);
                label = new Label(2, 5, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 5, 3, 5);
                label = new Label(4, 5, "使用预付:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 5, 5, 5);
                label = new Label(6, 5, objjson.getString("MONEY_PRE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 5, 7, 5);

                label = new Label(0, 6, "备注:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 6, 1, 6);
                label = new Label(2, 6, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 6, 3, 6);
                label = new Label(4, 6, "业务员:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 6, 5, 6);
                label = new Label(6, 6, "");
                wsheet.addCell(label);
                wsheet.mergeCells(6, 6, 7, 6);


                label = new Label(0, 7, "业务单号");
                wsheet.addCell(label);
                label = new Label(1, 7, "录单日期");
                wsheet.addCell(label);
                label = new Label(2, 7, "码洋");
                wsheet.addCell(label);
                label = new Label(3, 7, "折扣");
                wsheet.addCell(label);
                label = new Label(4, 7, "实洋");
                wsheet.addCell(label);
                label = new Label(5, 7, "本次收款");
                wsheet.addCell(label);
                label = new Label(6, 7, "备注");
                wsheet.addCell(label);

                label = new Label(0, 9, "户名：");
                wsheet.addCell(label);
                label = new Label(1, 9, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 9, 7, 9);

                label = new Label(0, 10, "联系人：");
                wsheet.addCell(label);
                label = new Label(1, 10, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 10, 7, 10);

                label = new Label(0, 11, "邮编：");
                wsheet.addCell(label);
                label = new Label(1, 11, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 11, 7, 11);

                label = new Label(0, 12, "地址：");
                wsheet.addCell(label);
                label = new Label(1, 12, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 12, 7, 12);

                label = new Label(0, 12, "电话：");
                wsheet.addCell(label);
                label = new Label(1, 12, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 12, 7, 12);

                label = new Label(0, 12, "传真：");
                wsheet.addCell(label);
                label = new Label(1, 12, "");
                wsheet.addCell(label);
                wsheet.mergeCells(1, 12, 7, 12);


            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);

                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    //设置表头
                    Label label = new Label(0, 0, "杭州果麦文化传媒有限公司收款单", wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 7, 0);

                    label = new Label(0, 1, "客户名称", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 1, 1, 1);
                    label = new Label(2, 1, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 1, 3, 1);
                    label = new Label(4, 1, "收款单号", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 1, 5, 1);
                    label = new Label(6, 1, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 1, 7, 1);

                    label = new Label(0, 2, "客户编号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("CLIENT_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 2, "部门编号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 2, "收款方式:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 2, objjson.getString("SK_CLASS").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 3, "录单日期:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 3, "收款人：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 3, "凭证编号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 3, objjson.getString("PZ_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 4, "站点编号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 4, objjson.getString("STATION_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 4, "支票汇票：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 4, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 4, "收款金额:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 4, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 5, "收款大写", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 5, 1, 5);
                    label = new Label(2, 5, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 5, 3, 5);
                    label = new Label(4, 5, "使用预付:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 5, 5, 5);
                    label = new Label(6, 5, objjson.getString("USE_DKMONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 5, 7, 5);

                    label = new Label(0, 6, "备注:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 6, 1, 6);
                    label = new Label(2, 6, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 6, 3, 6);
                    label = new Label(4, 6, "业务员:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 6, 5, 6);
                    label = new Label(6, 6, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 6, 7, 6);


                    label = new Label(0, 7, "业务单号");
                    wsheet.addCell(label);
                    label = new Label(1, 7, "录单日期");
                    wsheet.addCell(label);
                    label = new Label(2, 7, "码洋");
                    wsheet.addCell(label);
                    label = new Label(3, 7, "折扣");
                    wsheet.addCell(label);
                    label = new Label(4, 7, "实洋");
                    wsheet.addCell(label);
                    label = new Label(5, 7, "本次收款");
                    wsheet.addCell(label);
                    label = new Label(6, 7, "备注");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        Object object2 = list2.get(index);
                        System.out.println(object2.toString());
                        label = new Label(0, (i + 8), jsonObject.getString("DJ_CODE"));
                        wsheet.addCell(label);
                        String aString = jsonObject.get("INPUT_DATE").toString();
                        JSONObject jsonObjectinput = JSONObject.fromObject(aString);
                        Long d = Long.valueOf(jsonObjectinput.getString("time"));
                        Date date = new Date(d);
                        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
                        String string = s.format(date);
                        label = new Label(1, (i + 8), string);
                        wsheet.addCell(label);
                        label = new Label(2, (i + 8), jsonObject.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 8), jsonObject.getString("C_DISCOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(4, (i + 8), jsonObject.getString("REAL_MONEY").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(5, (i + 8), jsonObject.getString("NOW_MONEY").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(6, (i + 8), jsonObject.getString("MEMO").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                    }

                    label = new Label(0, 9 + list2.size() + 1, "户名：");
                    wsheet.addCell(label);
                    label = new Label(1, 9 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 9 + list2.size() + 1, 7, 9 + list2.size() + 1);

                    label = new Label(0, 10 + list2.size() + 1, "联系人：");
                    wsheet.addCell(label);
                    label = new Label(1, 10 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 10 + list2.size() + 1, 7, 10 + list2.size() + 1);

                    label = new Label(0, 11 + list2.size() + 1, "邮编：");
                    wsheet.addCell(label);
                    label = new Label(1, 11 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 11 + list2.size() + 1, 7, 11 + list2.size() + 1);

                    label = new Label(0, 12 + list2.size() + 1, "地址：");
                    wsheet.addCell(label);
                    label = new Label(1, 12 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 12 + list2.size() + 1, 7, 12 + list2.size() + 1);

                    label = new Label(0, 12 + list2.size() + 1, "电话：");
                    wsheet.addCell(label);
                    label = new Label(1, 12 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 12 + list2.size() + 1, 7, 12 + list2.size() + 1);

                    label = new Label(0, 12 + list2.size() + 1, "传真：");
                    wsheet.addCell(label);
                    label = new Label(1, 12 + list2.size() + 1, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 12 + list2.size() + 1, 7, 12 + list2.size() + 1);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 仓库调拨
     */
    @RequestMapping("jxlfords_fx_stocks_db1")
    @ResponseBody
    public String jxlfords_fx_stocks_db1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //					req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        try {
            String fileName = objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "") + "仓库调拨单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),
                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);
            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度


                wsheet.setRowView(1, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 5, 0);

                label = new Label(0, 2, "调出库房", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("DC_STOCK").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 2, "调入库房：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, objjson.getString("DR_STOCK").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 2, "单号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 2, objjson.getString("DB_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 3, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 3, 5, 3);
                wsheet.mergeCells(0, 4, 5, 4);

                label = new Label(0, 5, "书号");
                wsheet.addCell(label);
                label = new Label(1, 5, "商品名称");
                wsheet.addCell(label);
                label = new Label(2, 5, "作者");
                wsheet.addCell(label);
                label = new Label(3, 5, "出版社");
                wsheet.addCell(label);
                label = new Label(4, 5, "定价");
                wsheet.addCell(label);
                label = new Label(5, 5, "数量");
                wsheet.addCell(label);

                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 7, 5, overbase + 7);

                label = new Label(0, overbase + 8, "制单人：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(2, overbase + 8, "审核人：");
                wsheet.addCell(label);
                label = new Label(3, overbase + 8, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                label = new Label(4, overbase + 8, "出库人：");
                wsheet.addCell(label);
                label = new Label(5, overbase + 8, objjson.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);

                label = new Label(0, overbase + 10, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 10, 5, overbase + 10);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度


                    wsheet.setRowView(1, 0);

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 5, 0);

                    label = new Label(0, 2, "调出库房", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("DC_STOCK").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 2, "调入库房：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, objjson.getString("DR_STOCK").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 2, "单号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 2, objjson.getString("DB_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 3, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 3, 5, 3);
                    wsheet.mergeCells(0, 4, 5, 4);

                    label = new Label(0, 5, "书号");
                    wsheet.addCell(label);
                    label = new Label(1, 5, "商品名称");
                    wsheet.addCell(label);
                    label = new Label(2, 5, "作者");
                    wsheet.addCell(label);
                    label = new Label(3, 5, "出版社");
                    wsheet.addCell(label);
                    label = new Label(4, 5, "定价");
                    wsheet.addCell(label);
                    label = new Label(5, 5, "数量");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        System.out.println(jsonObject.toString());

                        label = new Label(0, (i + 6), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(1, (i + 6), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(2, (i + 6), jsonObject.getString("H_AUTHOR").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 6), jsonObject.getString("PUB_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(4, (i + 6), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(5, (i + 6), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);

                    }
                    wsheet.mergeCells(0, overbase + 7, 5, overbase + 7);

                    label = new Label(0, overbase + 8, "制单人：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, overbase + 8, "审核人：");
                    wsheet.addCell(label);
                    label = new Label(3, overbase + 8, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 8, "出库人：");
                    wsheet.addCell(label);
                    label = new Label(5, overbase + 8, objjson.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);

                    label = new Label(0, overbase + 10, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 10, 5, overbase + 10);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 出库
     */
    @RequestMapping("jxlfords_fx_os_ck1")
    @ResponseBody
    public String jxlfords_fx_os_ck1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //					req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        try {
            String fileName = "杭州果麦文化传媒有限公司其他出库单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),
                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);
            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 11, 0);

                label = new Label(0, 1, "出库类型：", wcfmt4);
                wsheet.addCell(label);

                String djtape = objjson.getString("DJ_TYPE");
                if ("TCCK".equals(djtape)) {
                    djtape = "组套明细出库";
                } else if ("CTCK".equals(djtape)) {
                    djtape = "拆套出库";
                } else if ("PKCK".equals(djtape)) {
                    djtape = "盘亏出库";
                } else if ("SCCK".equals(djtape)) {
                    djtape = "样书出库";
                } else if ("BSCK".equals(djtape)) {
                    djtape = "报损出库";
                } else if ("DSCK".equals(djtape)) {
                    djtape = "图书丢失";
                } else if ("JCCK".equals(djtape)) {
                    djtape = "借出出库";
                } else if ("JHCK".equals(djtape)) {
                    djtape = "借入还回";
                } else if ("YCCK".equals(djtape)) {
                    djtape = "商品移出";
                }


                label = new Label(1, 1, djtape, wcfmt4);
                wsheet.addCell(label);

                label = new Label(2, 1, "来源：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 1, objjson.getString("LAIYUANNAME"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 1, 5, 0);

                label = new Label(6, 1, "批次：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 1, objjson.getString("PICI"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(7, 1, 11, 1);

                label = new Label(0, 2, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 2, 11, 2);

                label = new Label(0, 3, "单据号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 3, 11, 3);

                label = new Label(0, 4, "库房");
                wsheet.addCell(label);

                label = new Label(1, 4, "书号");
                wsheet.addCell(label);

                label = new Label(2, 4, "商品名称");
                wsheet.addCell(label);

                label = new Label(3, 4, "定价");
                wsheet.addCell(label);

                label = new Label(4, 4, "数量");
                wsheet.addCell(label);

                label = new Label(5, 4, "有效库存");
                wsheet.addCell(label);

                label = new Label(6, 4, "折扣");
                wsheet.addCell(label);

                label = new Label(7, 4, "码洋");
                wsheet.addCell(label);

                label = new Label(8, 4, "实洋");
                wsheet.addCell(label);

                label = new Label(9, 4, "备注");
                wsheet.addCell(label);

                label = new Label(10, 4, "件册数");
                wsheet.addCell(label);

                label = new Label(11, 4, "出版社");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 7, 11, overbase + 7);


                label = new Label(0, overbase + 6, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 6, 11, overbase + 6);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 11, 0);

                    label = new Label(0, 1, "出库类型：", wcfmt4);
                    wsheet.addCell(label);
                    String djtape = objjson.getString("DJ_TYPE");
                    if ("TCCK".equals(djtape)) {
                        djtape = "组套明细出库";
                    } else if ("CTCK".equals(djtape)) {
                        djtape = "拆套出库";
                    } else if ("PKCK".equals(djtape)) {
                        djtape = "盘亏出库";
                    } else if ("SCCK".equals(djtape)) {
                        djtape = "样书出库";
                    } else if ("BSCK".equals(djtape)) {
                        djtape = "报损出库";
                    } else if ("DSCK".equals(djtape)) {
                        djtape = "图书丢失";
                    } else if ("JCCK".equals(djtape)) {
                        djtape = "借出出库";
                    } else if ("JHCK".equals(djtape)) {
                        djtape = "借入还回";
                    } else if ("YCCK".equals(djtape)) {
                        djtape = "商品移出";
                    }
                    label = new Label(1, 1, djtape, wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(2, 1, "来源：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 1, objjson.getString("LAIYUAN"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 1, 5, 0);

                    label = new Label(6, 1, "批次：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 1, objjson.getString("PICI"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, 1, 11, 1);

                    label = new Label(0, 2, "备注：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 2, 11, 2);

                    label = new Label(0, 3, "单据号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 3, 11, 3);


                    label = new Label(0, 4, "库房");
                    wsheet.addCell(label);

                    label = new Label(1, 4, "书号");
                    wsheet.addCell(label);

                    label = new Label(2, 4, "商品名称");
                    wsheet.addCell(label);

                    label = new Label(3, 4, "定价");
                    wsheet.addCell(label);

                    label = new Label(4, 4, "数量");
                    wsheet.addCell(label);

                    label = new Label(5, 4, "有效库存");
                    wsheet.addCell(label);

                    label = new Label(6, 4, "折扣");
                    wsheet.addCell(label);

                    label = new Label(7, 4, "码洋");
                    wsheet.addCell(label);

                    label = new Label(8, 4, "实洋");
                    wsheet.addCell(label);

                    label = new Label(9, 4, "备注");
                    wsheet.addCell(label);

                    label = new Label(10, 4, "件册数");
                    wsheet.addCell(label);

                    label = new Label(11, 4, "出版社");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        System.out.println(jsonObject.toString());

                        label = new Label(0, (i + 5), jsonObject.getString("STOCK_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(1, (i + 5), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(2, (i + 5), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 5), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(4, (i + 5), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(5, (i + 5), jsonObject.getString("STOCK_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(6, (i + 5), jsonObject.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(7, (i + 5), jsonObject.getString("TOTAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(8, (i + 5), jsonObject.getString("REAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(9, (i + 5), jsonObject.getString("MEMO").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(10, (i + 5), jsonObject.getString("PACKNUM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(11, (i + 5), jsonObject.getString("PUBID").replaceAll("&nbsp;", "").replace("null", ""));
                        wsheet.addCell(label);


                    }


                    label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 7, 5, overbase + 7);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 样书出库
     */
    @RequestMapping("jxlfords_fx_os_ck2")
    @ResponseBody
    public String jxlfords_fx_os_ck2(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //					req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        try {
            String fileName = objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "") + "样书出库单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),
                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);
            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 11, 0);

                label = new Label(0, 1, "出库类型：", wcfmt4);
                wsheet.addCell(label);

                String djtape = objjson.getString("DJ_TYPE");
                if ("TCCK".equals(djtape)) {
                    djtape = "组套明细出库";
                } else if ("CTCK".equals(djtape)) {
                    djtape = "拆套出库";
                } else if ("PKCK".equals(djtape)) {
                    djtape = "盘亏出库";
                } else if ("SCCK".equals(djtape)) {
                    djtape = "样书出库";
                } else if ("BSCK".equals(djtape)) {
                    djtape = "报损出库";
                } else if ("DSCK".equals(djtape)) {
                    djtape = "图书丢失";
                } else if ("JCCK".equals(djtape)) {
                    djtape = "借出出库";
                } else if ("JHCK".equals(djtape)) {
                    djtape = "借入还回";
                } else if ("YCCK".equals(djtape)) {
                    djtape = "商品移出";
                }


                label = new Label(1, 1, djtape, wcfmt4);
                wsheet.addCell(label);

                label = new Label(2, 1, "样书人：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 1, objjson.getString("M_NAME"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 1, 11, 0);

                label = new Label(0, 2, "批次：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("PICI"), wcfmt4);
                wsheet.addCell(label);


                label = new Label(2, 2, "电话：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, objjson.getString("M_TEL"), wcfmt4);
                wsheet.addCell(label);


                label = new Label(4, 2, "地址：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 2, objjson.getString("M_ADDRESS_SEND"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 2, 11, 2);

                label = new Label(0, 3, "单据号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                wsheet.addCell(label);

                label = new Label(2, 3, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 3, 11, 3);

                label = new Label(0, 4, "库房");
                wsheet.addCell(label);

                label = new Label(1, 4, "书号");
                wsheet.addCell(label);

                label = new Label(2, 4, "商品名称");
                wsheet.addCell(label);

                label = new Label(3, 4, "定价");
                wsheet.addCell(label);

                label = new Label(4, 4, "数量");
                wsheet.addCell(label);

                label = new Label(5, 4, "有效库存");
                wsheet.addCell(label);

                label = new Label(6, 4, "折扣");
                wsheet.addCell(label);

                label = new Label(7, 4, "码洋");
                wsheet.addCell(label);

                label = new Label(8, 4, "实洋");
                wsheet.addCell(label);

                label = new Label(9, 4, "备注");
                wsheet.addCell(label);

                label = new Label(10, 4, "件册数");
                wsheet.addCell(label);

                label = new Label(11, 4, "出版社");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 7, 11, overbase + 7);


                label = new Label(0, overbase + 6, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 6, 11, overbase + 6);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 11, 0);

                    label = new Label(0, 1, "出库类型：", wcfmt4);
                    wsheet.addCell(label);
                    String djtape = objjson.getString("DJ_TYPE");
                    if ("TCCK".equals(djtape)) {
                        djtape = "组套明细出库";
                    } else if ("CTCK".equals(djtape)) {
                        djtape = "拆套出库";
                    } else if ("PKCK".equals(djtape)) {
                        djtape = "盘亏出库";
                    } else if ("SCCK".equals(djtape)) {
                        djtape = "样书出库";
                    } else if ("BSCK".equals(djtape)) {
                        djtape = "报损出库";
                    } else if ("DSCK".equals(djtape)) {
                        djtape = "图书丢失";
                    } else if ("JCCK".equals(djtape)) {
                        djtape = "借出出库";
                    } else if ("JHCK".equals(djtape)) {
                        djtape = "借入还回";
                    } else if ("YCCK".equals(djtape)) {
                        djtape = "商品移出";
                    }
                    label = new Label(1, 1, djtape, wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(2, 1, "样书人：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 1, objjson.getString("M_NAME"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 1, 11, 0);

                    label = new Label(0, 2, "批次：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("PICI"), wcfmt4);
                    wsheet.addCell(label);


                    label = new Label(2, 2, "电话：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, objjson.getString("M_TEL"), wcfmt4);
                    wsheet.addCell(label);


                    label = new Label(4, 2, "地址：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 2, objjson.getString("M_ADDRESS_SEND"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 2, 11, 2);

                    label = new Label(0, 3, "单据号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(2, 3, "备注：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 3, 11, 3);


                    label = new Label(0, 4, "库房");
                    wsheet.addCell(label);

                    label = new Label(1, 4, "书号");
                    wsheet.addCell(label);

                    label = new Label(2, 4, "商品名称");
                    wsheet.addCell(label);

                    label = new Label(3, 4, "定价");
                    wsheet.addCell(label);

                    label = new Label(4, 4, "数量");
                    wsheet.addCell(label);

                    label = new Label(5, 4, "有效库存");
                    wsheet.addCell(label);

                    label = new Label(6, 4, "折扣");
                    wsheet.addCell(label);

                    label = new Label(7, 4, "码洋");
                    wsheet.addCell(label);

                    label = new Label(8, 4, "实洋");
                    wsheet.addCell(label);

                    label = new Label(9, 4, "备注");
                    wsheet.addCell(label);

                    label = new Label(10, 4, "件册数");
                    wsheet.addCell(label);

                    label = new Label(11, 4, "出版社");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        System.out.println(jsonObject.toString());

                        label = new Label(0, (i + 5), jsonObject.getString("STOCK_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(1, (i + 5), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(2, (i + 5), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 5), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(4, (i + 5), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(5, (i + 5), jsonObject.getString("STOCK_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(6, (i + 5), jsonObject.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(7, (i + 5), jsonObject.getString("TOTAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(8, (i + 5), jsonObject.getString("REAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(9, (i + 5), jsonObject.getString("MEMO").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(10, (i + 5), jsonObject.getString("PACKNUM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(11, (i + 5), jsonObject.getString("PUBID").replaceAll("&nbsp;", "").replace("null", ""));
                        wsheet.addCell(label);


                    }


                    label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 7, 5, overbase + 7);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 其他入库
     */
    @RequestMapping("jxlfords_fx_os_rk1")
    @ResponseBody
    public String jxlfords_fx_os_rk1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //					req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        try {
            String fileName = "杭州果麦文化传媒有限公司其他入库单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),
                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);
            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 11, 0);

                label = new Label(0, 1, "出库类型：", wcfmt4);
                wsheet.addCell(label);

                String djtape = objjson.getString("DJ_TYPE");
                if ("ZTRK".equals(djtape)) {
                    djtape = "组套入库";
                } else if ("CTRK".equals(djtape)) {
                    djtape = "拆套入库";
                } else if ("PYRK".equals(djtape)) {
                    djtape = "盘盈入库";
                } else if ("SRRK".equals(djtape)) {
                    djtape = "样书入库";
                } else if ("YRRK".equals(djtape)) {
                    djtape = "商品移入";
                } else if ("TERK".equals(djtape)) {
                    djtape = "拆套明细入库";
                } else if ("JRRK".equals(djtape)) {
                    djtape = "借入入库";
                } else if ("YDDH".equals(djtape)) {
                    djtape = "预订到货";
                } else if ("MB".equals(djtape)) {
                    djtape = "买榜";
                } else if ("HHRK".equals(djtape)) {
                    djtape = "借出还回";
                }


                label = new Label(1, 1, djtape, wcfmt4);
                wsheet.addCell(label);

                label = new Label(2, 1, "来源：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 1, objjson.getString("LAIYUANNAME"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 1, 5, 0);

                label = new Label(6, 1, "批次：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 1, objjson.getString("PICI"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(7, 1, 11, 1);

                label = new Label(0, 2, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 2, 11, 2);

                label = new Label(0, 3, "单据号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 3, 11, 3);

                label = new Label(0, 4, "库房");
                wsheet.addCell(label);

                label = new Label(1, 4, "书号");
                wsheet.addCell(label);

                label = new Label(2, 4, "商品名称");
                wsheet.addCell(label);

                label = new Label(3, 4, "定价");
                wsheet.addCell(label);

                label = new Label(4, 4, "数量");
                wsheet.addCell(label);

                label = new Label(5, 4, "有效库存");
                wsheet.addCell(label);

                label = new Label(6, 4, "折扣");
                wsheet.addCell(label);

                label = new Label(7, 4, "码洋");
                wsheet.addCell(label);

                label = new Label(8, 4, "实洋");
                wsheet.addCell(label);

                label = new Label(9, 4, "备注");
                wsheet.addCell(label);

                label = new Label(10, 4, "件册数");
                wsheet.addCell(label);

                label = new Label(11, 4, "出版社");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 7, 11, overbase + 7);


                label = new Label(0, overbase + 6, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 6, 11, overbase + 6);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 11, 0);

                    label = new Label(0, 1, "出库类型：", wcfmt4);
                    wsheet.addCell(label);
                    String djtape = objjson.getString("DJ_TYPE");
                    if ("ZTRK".equals(djtape)) {
                        djtape = "组套入库";
                    } else if ("CTRK".equals(djtape)) {
                        djtape = "拆套入库";
                    } else if ("PYRK".equals(djtape)) {
                        djtape = "盘盈入库";
                    } else if ("SRRK".equals(djtape)) {
                        djtape = "样书入库";
                    } else if ("YRRK".equals(djtape)) {
                        djtape = "商品移入";
                    } else if ("TERK".equals(djtape)) {
                        djtape = "拆套明细入库";
                    } else if ("JRRK".equals(djtape)) {
                        djtape = "借入入库";
                    } else if ("YDDH".equals(djtape)) {
                        djtape = "预订到货";
                    } else if ("MB".equals(djtape)) {
                        djtape = "买榜";
                    } else if ("HHRK".equals(djtape)) {
                        djtape = "借出还回";
                    }
                    label = new Label(1, 1, djtape, wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(2, 1, "来源：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 1, objjson.getString("LAIYUAN"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 1, 5, 0);

                    label = new Label(6, 1, "批次：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 1, objjson.getString("PICI"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, 1, 11, 1);

                    label = new Label(0, 2, "备注：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 2, 11, 2);

                    label = new Label(0, 3, "单据号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("OS_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 3, 11, 3);


                    label = new Label(0, 4, "库房");
                    wsheet.addCell(label);

                    label = new Label(1, 4, "书号");
                    wsheet.addCell(label);

                    label = new Label(2, 4, "商品名称");
                    wsheet.addCell(label);

                    label = new Label(3, 4, "定价");
                    wsheet.addCell(label);

                    label = new Label(4, 4, "数量");
                    wsheet.addCell(label);

                    label = new Label(5, 4, "有效库存");
                    wsheet.addCell(label);

                    label = new Label(6, 4, "折扣");
                    wsheet.addCell(label);

                    label = new Label(7, 4, "码洋");
                    wsheet.addCell(label);

                    label = new Label(8, 4, "实洋");
                    wsheet.addCell(label);

                    label = new Label(9, 4, "备注");
                    wsheet.addCell(label);

                    label = new Label(10, 4, "件册数");
                    wsheet.addCell(label);

                    label = new Label(11, 4, "出版社");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        System.out.println(jsonObject.toString());

                        label = new Label(0, (i + 5), jsonObject.getString("STOCK_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(1, (i + 5), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(2, (i + 5), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 5), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(4, (i + 5), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(5, (i + 5), jsonObject.getString("STOCK_AMOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(6, (i + 5), jsonObject.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(7, (i + 5), jsonObject.getString("TOTAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(8, (i + 5), jsonObject.getString("REAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(9, (i + 5), jsonObject.getString("MEMO").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(10, (i + 5), jsonObject.getString("PACKNUM").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(11, (i + 5), jsonObject.getString("PUBID").replaceAll("&nbsp;", "").replace("null", ""));
                        wsheet.addCell(label);


                    }


                    label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 7, 5, overbase + 7);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 销售退货
     */
    @RequestMapping("jxlfords_fx_xs1")
    @ResponseBody
    public String jxlfords_fx_xs1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售退货单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度


                wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 9, 0);

                label = new Label(0, 1, "客户名称", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 1, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 1, 3, 1);
                label = new Label(4, 1, "销售单号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 1, objjson.getString("PX_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 1, 6, 1);
                label = new Label(7, 1, "销售方式：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 1, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 1, 9, 1);

                label = new Label(0, 2, "客户编号", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 2, "单据序号", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 2, "总码洋：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 2, objjson.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 2, 6, 2);
                label = new Label(7, 2, "总实洋：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 2, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 2, 9, 2);

                label = new Label(0, 3, "电话：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("RECEIVE_TEL").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 3, "联系人：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, objjson.getString("RECEIVE_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 3, "总品种：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 3, objjson.getString("TOTAL_COUNT").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 3, 6, 3);
                label = new Label(7, 3, "总件数：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 3, objjson.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 3, 9, 3);

                label = new Label(0, 4, "退回日期：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 4, "总应收款：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 4, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 4, "平均折扣：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 4, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 4, 6, 4);
                label = new Label(7, 4, "总包册数：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 4, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 4, 9, 4);

                label = new Label(0, 5, "费用调整：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 5, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 5, "操作员：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 5, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 5, "实洋大写：", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 5, 9, 5);

                label = new Label(0, 6, "客户地址：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 6, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 6, 4, 6);
                label = new Label(4, 5, "业务主管：", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 6, 9, 6);

                label = new Label(0, 7, "业务员：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 7, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 7, "所属部门：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 7, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 7, "备注：", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 7, 9, 7);


                label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                wsheet.addCell(label);
                wsheet.mergeCells(0, 9, 9, 9);

                label = new Label(0, 11, "序号");
                wsheet.addCell(label);
                label = new Label(1, 11, "书号");
                wsheet.addCell(label);
                label = new Label(2, 11, "商品名称");
                wsheet.addCell(label);
                label = new Label(3, 11, "出版社");
                wsheet.addCell(label);
                label = new Label(4, 11, "定价");
                wsheet.addCell(label);
                label = new Label(5, 11, "折扣");
                wsheet.addCell(label);
                label = new Label(6, 11, "数量");
                wsheet.addCell(label);
                label = new Label(7, 11, "码洋");
                wsheet.addCell(label);
                label = new Label(8, 11, "实洋");
                wsheet.addCell(label);
                label = new Label(9, 11, "包册数");
                wsheet.addCell(label);

                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }
                wsheet.mergeCells(0, overbase + 13 + 1, 11, overbase + 13);

                label = new Label(0, overbase + 13 + 2, "制单人：");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 2, 1, overbase + 13 + 2);
                label = new Label(2, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(2, overbase + 13 + 2, 3, overbase + 13 + 2);
                label = new Label(4, overbase + 13 + 2, "审核人：");
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 2, 5, overbase + 13 + 2);
                label = new Label(6, overbase + 13 + 2, "");
                wsheet.addCell(label);
                wsheet.mergeCells(6, overbase + 13 + 2, 7, overbase + 13 + 2);
                label = new Label(8, overbase + 13 + 2, "出库人：");
                wsheet.addCell(label);
                wsheet.mergeCells(8, overbase + 13 + 2, 9, overbase + 13 + 2);
                label = new Label(10, overbase + 13 + 2, objjson2.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(10, overbase + 13 + 2, 11, overbase + 13 + 2);

                label = new Label(0, overbase + 13 + 4, "户名：");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 4, 1, overbase + 13 + 4);
                label = new Label(2, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(2, overbase + 13 + 4, 3, overbase + 13 + 4);
                label = new Label(4, overbase + 13 + 4, "联系人：");
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 4, 5, overbase + 13 + 4);
                label = new Label(6, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(6, overbase + 13 + 4, 7, overbase + 13 + 4);
                label = new Label(8, overbase + 13 + 4, "邮编：");
                wsheet.addCell(label);
                wsheet.mergeCells(8, overbase + 13 + 4, 9, overbase + 13 + 4);
                label = new Label(10, overbase + 13 + 4, objjson2.getString("COM_ZIP").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(10, overbase + 13 + 4, 11, overbase + 13 + 4);

                label = new Label(0, overbase + 13 + 5, "地址：");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 5, 1, overbase + 13 + 5);
                label = new Label(2, overbase + 13 + 5, objjson2.getString("COM_ADDRESS").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(2, overbase + 13 + 5, 3, overbase + 13 + 5);
                label = new Label(4, overbase + 13 + 5, "电话：");
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 5, 5, overbase + 13 + 5);
                label = new Label(6, overbase + 13 + 5, objjson2.getString("COM_TEL").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(6, overbase + 13 + 5, 7, overbase + 13 + 5);
                label = new Label(8, overbase + 13 + 5, "传真：");
                wsheet.addCell(label);
                wsheet.mergeCells(8, overbase + 13 + 5, 9, overbase + 13 + 5);
                label = new Label(10, overbase + 13 + 5, objjson2.getString("COM_FAX").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(10, overbase + 13 + 5, 11, overbase + 13 + 5);

                label = new Label(0, overbase + 13 + 6, "开户行：");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 6, 1, overbase + 13 + 6);
                label = new Label(2, overbase + 13 + 6, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(2, overbase + 13 + 6, 3, overbase + 13 + 6);
                label = new Label(4, overbase + 13 + 6, "账号：");
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 6, 5, overbase + 13 + 6);
                label = new Label(6, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(6, overbase + 13 + 6, 7, overbase + 13 + 6);
                label = new Label(8, overbase + 13 + 6, "邮箱：");
                wsheet.addCell(label);
                wsheet.mergeCells(8, overbase + 13 + 6, 9, overbase + 13 + 6);
                label = new Label(10, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                wsheet.addCell(label);
                wsheet.mergeCells(10, overbase + 13 + 6, 11, overbase + 13 + 6);

                label = new Label(0, overbase + 13 + 9, "验书：");
                wsheet.addCell(label);
                label = new Label(1, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                wsheet.mergeCells(1, overbase + 13 + 9, 2, overbase + 13 + 9);
                label = new Label(3, overbase + 13 + 9, "会计：");
                wsheet.addCell(label);
                label = new Label(4, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                wsheet.mergeCells(4, overbase + 13 + 9, 5, overbase + 13 + 9);
                label = new Label(6, overbase + 13 + 9, "经手人：");
                wsheet.addCell(label);
                label = new Label(7, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                wsheet.mergeCells(7, overbase + 13 + 9, 8, overbase + 13 + 9);
                label = new Label(9, overbase + 13 + 9, "收货人：");
                wsheet.addCell(label);
                label = new Label(10, overbase + 13 + 9, " ");
                wsheet.addCell(label);
                wsheet.mergeCells(10, overbase + 13 + 9, 11, overbase + 13 + 9);

                label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 11, 11, overbase + 13 + 11);
                label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 13, 11, overbase + 13 + 13);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    wsheet.setColumnView(9, 15); // 设置列的宽度
                    wsheet.setColumnView(10, 15); // 设置列的宽度
                    wsheet.setColumnView(11, 15); // 设置列的宽度


                    wsheet.setRowView(12, 0);

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 9, 0);

                    label = new Label(0, 1, "客户名称", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 1, objjson.getString("CLIENTS_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 1, 3, 1);
                    label = new Label(4, 1, "销售单号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 1, objjson.getString("PX_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 1, 6, 1);
                    label = new Label(7, 1, "销售方式：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 1, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 1, 9, 1);

                    label = new Label(0, 2, "客户编号", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 2, "单据序号", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, objjson.getString("CLIENTS_NO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 2, "总码洋：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 2, objjson.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 2, 6, 2);
                    label = new Label(7, 2, "总实洋：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 2, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 2, 9, 2);

                    label = new Label(0, 3, "电话：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("RECEIVE_TEL").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 3, "联系人：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, objjson.getString("RECEIVE_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 3, "总品种：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 3, objjson.getString("TOTAL_COUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 3, 6, 3);
                    label = new Label(7, 3, "总件数：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 3, objjson.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 3, 9, 3);

                    label = new Label(0, 4, "退回日期：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 4, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 4, "总应收款：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 4, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 4, "平均折扣：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 4, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 4, 6, 4);
                    label = new Label(7, 4, "总包册数：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 4, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 4, 9, 4);

                    label = new Label(0, 5, "费用调整：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 5, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 5, "操作员：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 5, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 5, "实洋大写：", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 5, 9, 5);

                    label = new Label(0, 6, "客户地址：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 6, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 6, 4, 6);
                    label = new Label(4, 5, "业务主管：", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 6, 9, 6);

                    label = new Label(0, 7, "业务员：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 7, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 7, "所属部门：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 7, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 7, "备注：", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 7, 9, 7);


                    label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 9, 11, 9);

                    label = new Label(0, 11, "序号");
                    wsheet.addCell(label);
                    label = new Label(1, 11, "书号");
                    wsheet.addCell(label);
                    label = new Label(2, 11, "商品名称");
                    wsheet.addCell(label);
                    label = new Label(3, 11, "出版社");
                    wsheet.addCell(label);
                    label = new Label(4, 11, "定价");
                    wsheet.addCell(label);
                    label = new Label(5, 11, "折扣");
                    wsheet.addCell(label);
                    label = new Label(6, 11, "数量");
                    wsheet.addCell(label);
                    label = new Label(7, 11, "码洋");
                    wsheet.addCell(label);
                    label = new Label(8, 11, "实洋");
                    wsheet.addCell(label);
                    label = new Label(9, 11, "包册数");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());

                            label = new Label(0, (i + 13), (i + 1) + "");
                            wsheet.addCell(label);
                            label = new Label(1, (i + 13), jsonObject.getString("H_ISBN").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 13), jsonObject.getString("H_NAME").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 13), jsonObject.getString("PUB_NAME").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 13), jsonObject.getString("H_PRICE").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 13), jsonObject.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 13), jsonObject.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(7, (i + 13), jsonObject.getString("TOTAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(8, (i + 13), jsonObject.getString("REAL_MONEY_ITEM").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            String bcsString = "";
                            try {
                                bcsString = jsonObject.getString("PACKNUM").replaceAll("&nbsp;", "");
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                            label = new Label(9, (i + 13), bcsString);
                            wsheet.addCell(label);
                        } catch (Exception e) {
                            System.out.println(e);
                            System.out.println(i);
                        }
                    }
                    wsheet.mergeCells(0, overbase + 13 + 1, 11, overbase + 13);

                    label = new Label(0, overbase + 13 + 2, "制单人：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 2, 1, overbase + 13 + 2);
                    label = new Label(2, overbase + 13 + 2, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, overbase + 13 + 2, 3, overbase + 13 + 2);
                    label = new Label(4, overbase + 13 + 2, "审核人：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 2, 5, overbase + 13 + 2);
                    label = new Label(6, overbase + 13 + 2, "");
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, overbase + 13 + 2, 7, overbase + 13 + 2);
                    label = new Label(8, overbase + 13 + 2, "出库人：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, overbase + 13 + 2, 9, overbase + 13 + 2);
                    label = new Label(10, overbase + 13 + 2, objjson2.getString("STOCK_MAN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, overbase + 13 + 2, 11, overbase + 13 + 2);

                    label = new Label(0, overbase + 13 + 4, "户名：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 4, 1, overbase + 13 + 4);
                    label = new Label(2, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, overbase + 13 + 4, 3, overbase + 13 + 4);
                    label = new Label(4, overbase + 13 + 4, "联系人：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 4, 5, overbase + 13 + 4);
                    label = new Label(6, overbase + 13 + 4, objjson2.getString("COM_PRINTNAME").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, overbase + 13 + 4, 7, overbase + 13 + 4);
                    label = new Label(8, overbase + 13 + 4, "邮编：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, overbase + 13 + 4, 9, overbase + 13 + 4);
                    label = new Label(10, overbase + 13 + 4, objjson2.getString("COM_ZIP").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, overbase + 13 + 4, 11, overbase + 13 + 4);

                    label = new Label(0, overbase + 13 + 5, "地址：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 5, 1, overbase + 13 + 5);
                    label = new Label(2, overbase + 13 + 5, objjson2.getString("COM_ADDRESS").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, overbase + 13 + 5, 3, overbase + 13 + 5);
                    label = new Label(4, overbase + 13 + 5, "电话：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 5, 5, overbase + 13 + 5);
                    label = new Label(6, overbase + 13 + 5, objjson2.getString("COM_TEL").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, overbase + 13 + 5, 7, overbase + 13 + 5);
                    label = new Label(8, overbase + 13 + 5, "传真：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, overbase + 13 + 5, 9, overbase + 13 + 5);
                    label = new Label(10, overbase + 13 + 5, objjson2.getString("COM_FAX").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, overbase + 13 + 5, 11, overbase + 13 + 5);

                    label = new Label(0, overbase + 13 + 6, "开户行：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 6, 1, overbase + 13 + 6);
                    label = new Label(2, overbase + 13 + 6, objjson2.getString("ACCOUNT_BANK1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, overbase + 13 + 6, 3, overbase + 13 + 6);
                    label = new Label(4, overbase + 13 + 6, "账号：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 6, 5, overbase + 13 + 6);
                    label = new Label(6, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, overbase + 13 + 6, 7, overbase + 13 + 6);
                    label = new Label(8, overbase + 13 + 6, "邮箱：");
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, overbase + 13 + 6, 9, overbase + 13 + 6);
                    label = new Label(10, overbase + 13 + 6, objjson2.getString("ACCOUNT_NO1").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, overbase + 13 + 6, 11, overbase + 13 + 6);

                    label = new Label(0, overbase + 13 + 9, "验书：");
                    wsheet.addCell(label);
                    label = new Label(1, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, overbase + 13 + 9, 2, overbase + 13 + 9);
                    label = new Label(3, overbase + 13 + 9, "会计：");
                    wsheet.addCell(label);
                    label = new Label(4, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, overbase + 13 + 9, 5, overbase + 13 + 9);
                    label = new Label(6, overbase + 13 + 9, "经手人：");
                    wsheet.addCell(label);
                    label = new Label(7, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, overbase + 13 + 9, 8, overbase + 13 + 9);
                    label = new Label(9, overbase + 13 + 9, "收货人：");
                    wsheet.addCell(label);
                    label = new Label(10, overbase + 13 + 9, " ");
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, overbase + 13 + 9, 11, overbase + 13 + 9);

                    label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 11, 11, overbase + 13 + 11);
                    label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 13, 11, overbase + 13 + 13);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 勾选导出前置传数据方法
     */
    @RequestMapping("gxdcadd")
    @ResponseBody
    public String gxdcadd(HttpSession session, String pkVal) {
        String rmark = "导出成功";
        session.setAttribute("pkVal", pkVal);
        return rmark;
    }

    /**
     * 勾选导出
     */
    @RequestMapping("gxdc")
    @ResponseBody
    public String gxdc(HttpServletRequest req, HttpServletResponse response, HttpSession session, String dsId) throws ParseException {
        String rmark = "导出成功";
        String pkVal = (String) session.getAttribute("pkVal");
        session.removeAttribute("pkVal");
        JSONArray list2 = JSONArray.fromObject(pkVal);
        List clnameList = printService.getsyscl(dsId);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");


        try {
            String fileName = "杭州果麦文化传媒有限公司";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),
                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);
            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;

            for (int t = 0; t < times; t++) {

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                for (int i = 0; i < clnameList.size(); i++) {
                    JSONObject jsonObject = JSONObject.fromObject(clnameList.get(i));
                    String name = jsonObject.getString("COLN_NAME");
                    Label label = new Label(i, 0, name);
                    wsheet.addCell(label);
                    //	wsheet.mergeCells(i, 0, 11, 0);
                }


                for (int i = 0; i < list2.size(); i++) {
                    JSONObject jsonObject = JSONObject.fromObject(list2.get(i));
                    for (int j = 0; j < clnameList.size(); j++) {
                        JSONObject jsonObject2 = JSONObject.fromObject(clnameList.get(j));
					/*	if ("baseInfo".equals(jsonObject2.getString("NAME"))) {
							continue;
						}*/
                        String valueString = jsonObject.getString(jsonObject2.getString("NAME"));
                        String editType = jsonObject2.getString("EDITYPE") == null ? "" : jsonObject2.getString("EDITYPE");
                        List<Map<String, Object>> list = MenuController.mapList.get(editType);

                        try {
                            if ("formatDate".equals(jsonObject2.getString("FORMAT_CONT"))) {
                                valueString = simpleDateFormat.format(new Date(Long.valueOf(valueString)));
                            }
                        } catch (Exception e) {
                            // TODO: handle exception
                        }

                        if (editType == null || "".equals(editType) || "null".equals(editType)) {
                            Label label = new Label(j, i + 1, valueString);
                            wsheet.addCell(label);
                        } else {
                            for (int k = 0; k < list.size(); k++) {
                                if (list.get(k).get("ID").equals(valueString)) {
                                    Label label = new Label(j, i + 1, list.get(k).get("NAME").toString());
                                    wsheet.addCell(label);
                                    break;
                                }
                            }
                        }

                    }
                }



				/*label = new Label(0,list2.size()+2,"技术支持：上海爱你特科技  www.ainit.cn" );
				wsheet.addCell(label);
				wsheet.mergeCells(0, list2.size()+2,5, list2.size()+2);*/
            }


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 客户添货
     */
    @RequestMapping("jxlfords_fx_zd1")
    @ResponseBody
    public String jxlfords_fx_zd1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售客户添货单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度
                wsheet.setColumnView(12, 15); // 设置列的宽度
                //wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 12, 0);

                label = new Label(0, 1, "客户名称:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 1, 1, 1);
                label = new Label(2, 1, objjson.getString("C_ID"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 1, 7, 1);
                label = new Label(8, 1, "单号:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 1, 9, 1);
                label = new Label(10, 1, objjson.getString("DJ_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(10, 1, 12, 1);

                label = new Label(0, 2, "对方单号:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 2, 1, 2);
                label = new Label(2, 2, "", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 2, 3, 2);
                label = new Label(4, 2, "片区经理:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 2, 5, 2);
                label = new Label(6, 2, objjson.getString("O_ID_LASTGR"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 2, 7, 2);
                label = new Label(8, 2, "选择地址:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 2, 9, 2);
                label = new Label(10, 2, objjson.getString("C_AD_ID"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(10, 2, 12, 2);

                label = new Label(0, 3, "收件人:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 3, 1, 3);
                label = new Label(2, 3, objjson.getString("C_AD_CONTACTMAN"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 3, 3, 3);
                label = new Label(4, 3, "收件电话:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 3, 5, 3);
                label = new Label(6, 3, objjson.getString("C_AD_CONTACTTEL"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 3, 7, 3);
                label = new Label(8, 3, "收件地址:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(8, 3, 9, 3);
                label = new Label(10, 3, objjson.getString("C_AD_ADDRESS"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(10, 3, 12, 3);

                label = new Label(0, 4, "备注:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 4, 1, 4);
                label = new Label(2, 4, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 4, 12, 4);


                label = new Label(0, 5, "书号");
                wsheet.addCell(label);
                label = new Label(1, 5, "商品名称");
                wsheet.addCell(label);
                label = new Label(2, 5, "库房");
                wsheet.addCell(label);
                label = new Label(3, 5, "定价");
                wsheet.addCell(label);
                label = new Label(4, 5, "折扣");
                wsheet.addCell(label);
                label = new Label(5, 5, "实价");
                wsheet.addCell(label);
                label = new Label(6, 5, "订单数");
                wsheet.addCell(label);
                label = new Label(7, 5, "件册数");
                wsheet.addCell(label);
                label = new Label(8, 5, "有效库存");
                wsheet.addCell(label);
                label = new Label(9, 5, "总码洋");
                wsheet.addCell(label);
                label = new Label(10, 5, "总实洋");
                wsheet.addCell(label);
                label = new Label(11, 5, "商品分类");
                wsheet.addCell(label);
                label = new Label(12, 5, "出版社");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }


                label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 7, 12, overbase + 7);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    wsheet.setColumnView(9, 15); // 设置列的宽度
                    wsheet.setColumnView(10, 15); // 设置列的宽度
                    wsheet.setColumnView(11, 15); // 设置列的宽度
                    wsheet.setColumnView(12, 15); // 设置列的宽度


                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 12, 0);

                    label = new Label(0, 1, "客户名称:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 1, 1, 1);
                    label = new Label(2, 1, objjson.getString("C_ID"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 1, 7, 1);
                    label = new Label(8, 1, "单号:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 1, 9, 1);
                    label = new Label(10, 1, objjson.getString("DJ_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, 1, 12, 1);

                    label = new Label(0, 2, "对方单号:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 2, 1, 2);
                    label = new Label(2, 2, "", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 2, 3, 2);
                    label = new Label(4, 2, "片区经理:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 2, 5, 2);
                    label = new Label(6, 2, objjson.getString("O_ID_LASTGR"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 2, 7, 2);
                    label = new Label(8, 2, "选择地址:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 2, 9, 2);
                    label = new Label(10, 2, objjson.getString("C_AD_ID"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, 2, 12, 2);

                    label = new Label(0, 3, "收件人:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 3, 1, 3);
                    label = new Label(2, 3, objjson.getString("C_AD_CONTACTMAN"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 3, 3, 3);
                    label = new Label(4, 3, "收件电话:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 3, 5, 3);
                    label = new Label(6, 3, objjson.getString("C_AD_CONTACTTEL"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 3, 7, 3);
                    label = new Label(8, 3, "收件地址:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(8, 3, 9, 3);
                    label = new Label(10, 3, objjson.getString("C_AD_ADDRESS"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, 3, 12, 3);

                    label = new Label(0, 4, "备注:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 4, 1, 4);
                    label = new Label(2, 4, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 4, 12, 4);


                    label = new Label(0, 5, "书号");
                    wsheet.addCell(label);
                    label = new Label(1, 5, "商品名称");
                    wsheet.addCell(label);
                    label = new Label(2, 5, "库房");
                    wsheet.addCell(label);
                    label = new Label(3, 5, "定价");
                    wsheet.addCell(label);
                    label = new Label(4, 5, "折扣");
                    wsheet.addCell(label);
                    label = new Label(5, 5, "实价");
                    wsheet.addCell(label);
                    label = new Label(6, 5, "订单数");
                    wsheet.addCell(label);
                    label = new Label(7, 5, "件册数");
                    wsheet.addCell(label);
                    label = new Label(8, 5, "有效库存");
                    wsheet.addCell(label);
                    label = new Label(9, 5, "总码洋");
                    wsheet.addCell(label);
                    label = new Label(10, 5, "总实洋");
                    wsheet.addCell(label);
                    label = new Label(11, 5, "商品分类");
                    wsheet.addCell(label);
                    label = new Label(12, 5, "出版社");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            label = new Label(0, (i + 6), jsonObject.getString("H_ISBN"));
                            wsheet.addCell(label);
                            label = new Label(1, (i + 6), jsonObject.getString("H_NAME"));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 6), jsonObject.getString("STOCK_ID"));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 6), jsonObject.getString("H_PRICE"));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 6), jsonObject.getString("H_DISCOUNT"));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 6), jsonObject.getString("H_PRICE_REAL"));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 6), jsonObject.getString("H_AMOUNT"));
                            wsheet.addCell(label);
                            label = new Label(7, (i + 6), jsonObject.getString("PACKNUM"));
                            wsheet.addCell(label);
                            label = new Label(8, (i + 6), jsonObject.getString("SORT_NUMBER"));
                            wsheet.addCell(label);
                            label = new Label(9, (i + 6), jsonObject.getString("TOTAL_MONEY_ITEM"));
                            wsheet.addCell(label);
                            label = new Label(10, (i + 6), jsonObject.getString("REAL_MONEY_ITEM"));
                            wsheet.addCell(label);
                            label = new Label(11, (i + 6), jsonObject.getString("H_TYPE"));
                            wsheet.addCell(label);
                            label = new Label(12, (i + 6), jsonObject.getString("PUB_NAME"));
                            wsheet.addCell(label);


                        } catch (Exception e) {

                        }
                    }

                    label = new Label(0, overbase + 9, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9, 12, overbase + 9);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 印厂入库导出
     */
    @RequestMapping("jxlfords_fx_jh1")
    @ResponseBody
    public String jxlfords_fx_jh1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售客户添货单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度
                wsheet.setColumnView(12, 15); // 设置列的宽度
                wsheet.setColumnView(13, 15); // 设置列的宽度

                //wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 13, 0);

                label = new Label(0, 1, "印厂:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 1, 1, 1);
                label = new Label(2, 1, objjson.getString("MAN_ID"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 1, 4, 1);
                label = new Label(5, 1, "对方单号:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 1, 6, 1);
                label = new Label(7, 1, objjson.getString("JH_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(7, 1, 9, 1);
                label = new Label(10, 1, "进货方式:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(10, 1, 11, 1);
                label = new Label(12, 1, objjson.getString("JH_STYLE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(12, 1, 13, 1);

                label = new Label(0, 2, "发票类别:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 2, 1, 2);
                label = new Label(2, 2, objjson.getString("INV_STYPE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 2, 4, 2);
                label = new Label(5, 2, "到货时间:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 2, 6, 2);
                label = new Label(7, 2, objjson.getString("JH_DATE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(7, 2, 9, 2);
                label = new Label(10, 2, "单据号:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(10, 2, 11, 2);
                label = new Label(12, 2, objjson.getString("JH_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(12, 2, 13, 2);

                label = new Label(0, 3, "备注:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 3, 1, 3);
                label = new Label(2, 3, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 3, 13, 3);


                label = new Label(0, 5, "库房");
                wsheet.addCell(label);
                label = new Label(1, 5, "书号");
                wsheet.addCell(label);
                label = new Label(2, 5, "商品名称");
                wsheet.addCell(label);
                label = new Label(3, 5, "定价");
                wsheet.addCell(label);
                label = new Label(4, 5, "印次");
                wsheet.addCell(label);
                label = new Label(5, 5, "数量");
                wsheet.addCell(label);
                label = new Label(6, 5, "折扣");
                wsheet.addCell(label);
                label = new Label(7, 5, "单品实价");
                wsheet.addCell(label);
                label = new Label(8, 5, "码洋");
                wsheet.addCell(label);
                label = new Label(9, 5, "实洋");
                wsheet.addCell(label);
                label = new Label(10, 5, "备注");
                wsheet.addCell(label);
                label = new Label(11, 5, "商品分类");
                wsheet.addCell(label);
                label = new Label(12, 5, "出版社");
                wsheet.addCell(label);
                label = new Label(13, 5, "件册数");
                wsheet.addCell(label);

                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }


                label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 7, 12, overbase + 7);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    wsheet.setColumnView(9, 15); // 设置列的宽度
                    wsheet.setColumnView(10, 15); // 设置列的宽度
                    wsheet.setColumnView(11, 15); // 设置列的宽度
                    wsheet.setColumnView(12, 15); // 设置列的宽度
                    wsheet.setColumnView(13, 15); // 设置列的宽度

                    //wsheet.setRowView(12, 0);

                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 13, 0);

                    label = new Label(0, 1, "印厂:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 1, 1, 1);
                    label = new Label(2, 1, objjson.getString("MAN_ID"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 1, 4, 1);
                    label = new Label(5, 1, "对方单号:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 1, 6, 1);
                    label = new Label(7, 1, objjson.getString("JH_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, 1, 9, 1);
                    label = new Label(10, 1, "进货方式:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, 1, 11, 1);
                    label = new Label(12, 1, objjson.getString("JH_STYLE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(12, 1, 13, 1);

                    label = new Label(0, 2, "发票类别:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 2, 1, 2);
                    label = new Label(2, 2, objjson.getString("INV_STYPE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 2, 4, 2);
                    label = new Label(5, 2, "到货时间:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 2, 6, 2);
                    label = new Label(7, 2, objjson.getString("JH_DATE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(7, 2, 9, 2);
                    label = new Label(10, 2, "单据号:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(10, 2, 11, 2);
                    label = new Label(12, 2, objjson.getString("JH_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(12, 2, 13, 2);

                    label = new Label(0, 3, "备注:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 3, 1, 3);
                    label = new Label(2, 3, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 3, 13, 3);


                    label = new Label(0, 5, "库房");
                    wsheet.addCell(label);
                    label = new Label(1, 5, "书号");
                    wsheet.addCell(label);
                    label = new Label(2, 5, "商品名称");
                    wsheet.addCell(label);
                    label = new Label(3, 5, "定价");
                    wsheet.addCell(label);
                    label = new Label(4, 5, "印次");
                    wsheet.addCell(label);
                    label = new Label(5, 5, "数量");
                    wsheet.addCell(label);
                    label = new Label(6, 5, "折扣");
                    wsheet.addCell(label);
                    label = new Label(7, 5, "单品实价");
                    wsheet.addCell(label);
                    label = new Label(8, 5, "码洋");
                    wsheet.addCell(label);
                    label = new Label(9, 5, "实洋");
                    wsheet.addCell(label);
                    label = new Label(10, 5, "备注");
                    wsheet.addCell(label);
                    label = new Label(11, 5, "商品分类");
                    wsheet.addCell(label);
                    label = new Label(12, 5, "出版社");
                    wsheet.addCell(label);
                    label = new Label(13, 5, "件册数");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());
                            label = new Label(0, (i + 6), jsonObject.getString("STOCK_ID"));
                            wsheet.addCell(label);
                            label = new Label(1, (i + 6), jsonObject.getString("H_ISBN"));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 6), jsonObject.getString("H_NAME"));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 6), jsonObject.getString("H_PRICE"));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 6), jsonObject.getString("YINCI"));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 6), jsonObject.getString("H_AMOUNT"));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 6), jsonObject.getString("H_DISCOUNT"));
                            wsheet.addCell(label);
                            label = new Label(7, (i + 6), jsonObject.getString("H_PRICE_REAL"));
                            wsheet.addCell(label);
                            label = new Label(8, (i + 6), jsonObject.getString("TOTAL_MONEY_ITEM"));
                            wsheet.addCell(label);
                            label = new Label(9, (i + 6), jsonObject.getString("REAL_MONEY_ITEM"));
                            wsheet.addCell(label);
                            label = new Label(10, (i + 6), jsonObject.getString("MEMO"));
                            wsheet.addCell(label);
                            label = new Label(11, (i + 6), jsonObject.getString("H_TYPE"));
                            wsheet.addCell(label);
                            label = new Label(12, (i + 6), jsonObject.getString("PUB_NAME"));
                            wsheet.addCell(label);
                            label = new Label(13, (i + 6), jsonObject.getString("PACKNUM"));
                            wsheet.addCell(label);


                        } catch (Exception e) {

                        }
                    }

                    label = new Label(0, overbase + 9, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9, 13, overbase + 9);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    /**
     * 开票单导出
     */
    @RequestMapping("jxlfords_fx_invoice_kp1")
    @ResponseBody
    public String jxlfords_fx_invoice_kp1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售开票单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度
                wsheet.setColumnView(12, 15); // 设置列的宽度
                wsheet.setColumnView(13, 15); // 设置列的宽度

                //wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 7, 0);

                label = new Label(0, 1, "客户名称:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 1, objjson.getString("CLIENTS_NAME"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 1, 3, 1);
                label = new Label(4, 1, "片区经理:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 1, objjson.getString("O_ID_LASTGR"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 1, "对账单号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 1, objjson.getString("O_ID_LASTGR"), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 2, "账单金额:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("JS_ID"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 2, "发票金额:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, objjson.getString("THIS_YS_MONEY"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 2, "发票类型:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 2, objjson.getString("NAME"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 2, "开票内容:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 2, objjson.getString("INV_CONTENT"), wcfmt4);
                wsheet.addCell(label);


                label = new Label(0, 3, "开票日期:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("INVOICE_DATE"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 3, "发票号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, objjson.getString("INVOICE_NO"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(4, 3, "单据号:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(5, 3, objjson.getString("INV_CODE"), wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 3, "", wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 3, "", wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 4, "备注:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, objjson.getString("O_ID_LASTGR"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 4, 7, 4);


                label = new Label(0, 5, "业务单号");
                wsheet.addCell(label);
                label = new Label(1, 5, "出入日期");
                wsheet.addCell(label);
                label = new Label(2, 5, "码洋");
                wsheet.addCell(label);
                label = new Label(3, 5, "折扣");
                wsheet.addCell(label);
                label = new Label(4, 5, "实洋");
                wsheet.addCell(label);
                label = new Label(5, 5, "本次开票");
                wsheet.addCell(label);
                label = new Label(6, 5, "备注");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }


                label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 7, 12, overbase + 7);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    wsheet.setColumnView(9, 15); // 设置列的宽度
                    wsheet.setColumnView(10, 15); // 设置列的宽度
                    wsheet.setColumnView(11, 15); // 设置列的宽度
                    wsheet.setColumnView(12, 15); // 设置列的宽度
                    wsheet.setColumnView(13, 15); // 设置列的宽度

                    //wsheet.setRowView(12, 0);
                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 7, 0);

                    label = new Label(0, 1, "客户名称:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 1, objjson.getString("CLIENTS_NAME"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 1, 3, 1);
                    label = new Label(4, 1, "片区经理:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 1, objjson.getString("O_ID_LASTGR"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 1, "对账单号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 1, objjson.getString("O_ID_LASTGR"), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 2, "账单金额:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("JS_ID"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 2, "发票金额:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, objjson.getString("THIS_YS_MONEY"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 2, "发票类型:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 2, objjson.getString("NAME"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 2, "开票内容:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 2, objjson.getString("INV_CONTENT"), wcfmt4);
                    wsheet.addCell(label);


                    label = new Label(0, 3, "开票日期:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("INVOICE_DATE"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 3, "发票号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, objjson.getString("INVOICE_NO"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(4, 3, "单据号:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(5, 3, objjson.getString("INV_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 3, "", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 3, "", wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 4, "备注:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 4, objjson.getString("O_ID_LASTGR"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 4, 7, 4);


                    label = new Label(0, 5, "业务单号");
                    wsheet.addCell(label);
                    label = new Label(1, 5, "出入日期");
                    wsheet.addCell(label);
                    label = new Label(2, 5, "码洋");
                    wsheet.addCell(label);
                    label = new Label(3, 5, "折扣");
                    wsheet.addCell(label);
                    label = new Label(4, 5, "实洋");
                    wsheet.addCell(label);
                    label = new Label(5, 5, "本次开票");
                    wsheet.addCell(label);
                    label = new Label(6, 5, "备注");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());
                            label = new Label(0, (i + 6), jsonObject.getString("DJ_CODE"));
                            wsheet.addCell(label);
                            String daString = jsonObject.getString("INPUT_DATE");
                            JSONObject jsonObjectd = JSONObject.fromObject(daString);
                            Long long1 = jsonObjectd.getLong("time");
                            daString = simpleDateFormat.format(new Date(long1));

                            label = new Label(1, (i + 6), daString);
                            wsheet.addCell(label);
                            label = new Label(2, (i + 6), jsonObject.getString("TOTAL_MONEY"));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 6), jsonObject.getString("C_DISCOUNT"));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 6), jsonObject.getString("REAL_MONEY"));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 6), jsonObject.getString("NOW_MONEY"));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 6), jsonObject.getString("MEMO"));
                            wsheet.addCell(label);


                        } catch (Exception e) {

                        }
                    }

                    label = new Label(0, overbase + 9, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9, 13, overbase + 9);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    //jxlfords_bj_fkd1
/*	预付单导出*/

    @RequestMapping("jxlfords_bj_fkd1")
    @ResponseBody
    public String jxlfords_bj_fkd1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售预付单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //大循环


            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + 1, 0);
            //设置表头
            //设置宽度
            wsheet.setColumnView(0, 15); // 设置列的宽度
            wsheet.setColumnView(1, 15); // 设置列的宽度
            wsheet.setColumnView(2, 15); // 设置列的宽度
            wsheet.setColumnView(3, 15); // 设置列的宽度
            wsheet.setColumnView(4, 15); // 设置列的宽度
            wsheet.setColumnView(5, 15); // 设置列的宽度
            wsheet.setColumnView(6, 15); // 设置列的宽度
            wsheet.setColumnView(7, 15); // 设置列的宽度
            wsheet.setColumnView(8, 15); // 设置列的宽度
            wsheet.setColumnView(9, 15); // 设置列的宽度
            wsheet.setColumnView(10, 15); // 设置列的宽度
            wsheet.setColumnView(11, 15); // 设置列的宽度
            wsheet.setColumnView(12, 15); // 设置列的宽度
            wsheet.setColumnView(13, 15); // 设置列的宽度

            //wsheet.setRowView(12, 0);

            Label label = new Label(0, 0, fileName, wcfmt1);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "基本信息");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 1, 7, 1);

            label = new Label(0, 2, "付款对象:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("M_NAME"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 3, 2);
            label = new Label(4, 2, "选题名称:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 2, objjson.getString("XT_NAME"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(5, 2, 7, 2);

            label = new Label(0, 3, "预付金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 3, objjson.getString("REAL_MONEY"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 3, "账号:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 3, objjson.getString("BANK_NO"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 3, "开户行:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 3, objjson.getString("BANK_NAME"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(5, 3, 7, 3);

            label = new Label(0, 4, "事项:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 4, objjson.getString("SHIXIANG"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(1, 4, 7, 4);

            label = new Label(0, 5, "最迟付款日:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 5, objjson.getString("LAST_PAY_DATE").replace("&nbsp;00:00:00.0", ""), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 5, "类型:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 5, objjson.getString("MARKET_TYPES"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 5, "营销预算余额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 5, objjson.getString("MARKET_BUDGET_BALANCE"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(6, 5, "产品经理:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(7, 5, objjson.getString("ZEREN_BIANJI"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(0, 6, "预付余额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 6, objjson.getString("YJ_REST_MONEY"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(2, 6, "占用金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 6, objjson.getString("YJ_MONEY_LOCK"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(4, 6, "已使用金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 6, objjson.getString("YJ_USE_MONEY"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(6, 6, "出版社:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(7, 6, objjson.getString("PUB_ID"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(0, 7, "作者:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 7, objjson.getString("AUTHOR"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 7, "译者:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 7, objjson.getString("TRANSLATOR"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 7, "单据号:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 7, objjson.getString("DJ_CODE"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(0, 8, "技术支持：上海爱你特科技  www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 13, 7, 13);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    //jxlfords_bj_jkd1
/*	借款单导出*/

    @RequestMapping("jxlfords_bj_jkd1")
    @ResponseBody
    public String jxlfords_bj_jkd1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司销售借款单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //大循环


            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + 1, 0);
            //设置表头
            //设置宽度
            wsheet.setColumnView(0, 15); // 设置列的宽度
            wsheet.setColumnView(1, 15); // 设置列的宽度
            wsheet.setColumnView(2, 15); // 设置列的宽度
            wsheet.setColumnView(3, 15); // 设置列的宽度
            wsheet.setColumnView(4, 15); // 设置列的宽度
            wsheet.setColumnView(5, 15); // 设置列的宽度
            wsheet.setColumnView(6, 15); // 设置列的宽度
            wsheet.setColumnView(7, 15); // 设置列的宽度
            wsheet.setColumnView(8, 15); // 设置列的宽度
            wsheet.setColumnView(9, 15); // 设置列的宽度
            wsheet.setColumnView(10, 15); // 设置列的宽度
            wsheet.setColumnView(11, 15); // 设置列的宽度
            wsheet.setColumnView(12, 15); // 设置列的宽度
            wsheet.setColumnView(13, 15); // 设置列的宽度

            //wsheet.setRowView(12, 0);

            Label label = new Label(0, 0, fileName, wcfmt1);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "基本信息");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 1, 7, 1);

            label = new Label(0, 2, "付款对象:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("MAN_BUSINESSES"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 3, 2);
            label = new Label(4, 2, "选题名称:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 2, objjson.getString("XT_NAME"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(5, 2, 7, 2);

            label = new Label(0, 3, "预付金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 3, objjson.getString("REAL_MONEY"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 3, "账号:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 3, objjson.getString("BANK_NO"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 3, "开户行:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 3, objjson.getString("BANK_NAME"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(5, 3, 7, 3);

            label = new Label(0, 4, "事项:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 4, objjson.getString("SHIXIANG"), wcfmt4);
            wsheet.addCell(label);
            wsheet.mergeCells(1, 4, 7, 4);

            label = new Label(0, 5, "最迟付款日:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 5, objjson.getString("LAST_PAY_DATE").replace("&nbsp;00:00:00.0", ""), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 5, "类型:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 5, objjson.getString("MARKET_TYPES"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 5, "营销预算余额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 5, objjson.getString("MARKET_BUDGET_BALANCE"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(6, 5, "产品经理:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(7, 5, objjson.getString("ZEREN_BIANJI"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(0, 6, "预付余额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 6, objjson.getString("YJ_REST_MONEY"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(2, 6, "占用金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 6, objjson.getString("YJ_MONEY_LOCK"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(4, 6, "已使用金额:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 6, objjson.getString("YJ_USE_MONEY"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(6, 6, "出版社:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(7, 6, objjson.getString("PUB_ID"), wcfmt4);
            wsheet.addCell(label);


            label = new Label(0, 7, "作者:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(1, 7, objjson.getString("AUTHOR"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(2, 7, "译者:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(3, 7, objjson.getString("TRANSLATOR"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(4, 7, "单据号:", wcfmt4);
            wsheet.addCell(label);
            label = new Label(5, 7, objjson.getString("DJ_CODE"), wcfmt4);
            wsheet.addCell(label);

            label = new Label(0, 8, "技术支持：上海爱你特科技  www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 13, 7, 13);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }


    //jxlfords_cw_reviewFee1

    /**
     * 审稿费预付明细
     * <p/>
     * jxlfords_cw_reviewFee1
     * ds_cw_reviewFee1
     */
    @RequestMapping("jxlfords_cw_reviewFee1")
    @ResponseBody
    public String jxlfords_cw_reviewFee1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单

            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是审稿费单打印
                if ("ds_cw_reviewFee1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);
                    list2 = dateList;

//                    String VENDOR_ID = JSONObject.fromObject(object).getString("VENDOR_ID").replaceAll("&nbsp;", "");
//                    String MMSQL = "SELECT (TO_CHAR(VV.IS_STOKETIME, 'yyyy-mm-dd')) IS_STOKETIME, VV.DJ_CODE, (select STATUS_NAME from (SELECT 'IN' STATUS_ID, '纸张入库单' STATUS_NAME from dual UNION ALL SELECT 'TH' STATUS_ID, '纸张退货单' STATUS_NAME from dual UNION ALL SELECT 'RK' STATUS_ID, '纸张其他入库单' STATUS_NAME from dual) aa where aa.STATUS_ID = VV.DJ_TYPE) DJ_TYPE, VV.CL_HETONGHAO, (select b.cl_name from bs_material b where b.cl_id = VV.CL_ID) CL_NAME, VV.CL_STANDARD, VV.CL_PRICE, (select name from bs_comparison where comparison_id = 'cljlUnit' and codeId = VV.CL_UNIT) CL_UNIT, VV.TOTAL_AMOUNT, VV.REAL_MONEY, VV.TAX_RATE, VV.TAX_MONEY, VV.MX_BHMONEYSUM FROM VV_CW_ZCDZ VV left join bs_man on bs_man.man_id=vv.VENDOR_ID WHERE VV.I_INFO NOT IN (SELECT CMI.I_INFO FROM cw_clreconcid_item CMI LEFT JOIN CW_CLRECONCID CM ON CMI.CL_ID = CM.CL_ID WHERE cm.is_destroy = '0') AND bs_man.m_name='"+VENDOR_ID+"'";
//                    list3=printService.getPrintMMList(MMSQL);

                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //2.4 最后将主表数据设置上

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());


        try {
            String fileName = objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "") + "审稿费预付单";
            //         String fileName="纸厂对账";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);
            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    13, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            //有边框
            WritableFont wtf5 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt5 = new WritableCellFormat(wtf5);
            wcfmt5.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);
            wcfmt5.setBorder(jxl.format.Border.LEFT, BorderLineStyle.THIN);


            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度


                wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 8, 0);

                label = new Label(0, 2, "出版社：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 2, objjson.getString("PUB_ID").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 2, "账户号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 2, objjson.getString("CARD_NO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 2, 2, 2);
                label = new Label(5, 2, "账户名：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 2, objjson.getString("ACCOUNT_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 2, "开户行：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 2, objjson.getString("BANK_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);


                label = new Label(0, 3, "预付金额:", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 3, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 3, "占用金额：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 3, " ", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 3, 4, 3);
                label = new Label(5, 3, "已使用金额：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 3, objjson.getString("TOTAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(7, 3, "预付余额：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(8, 3, objjson.getString("REAL_MONEY").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);

                label = new Label(0, 4, "单据号：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 4, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                label = new Label(2, 4, "录单员：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(3, 4, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 4, 4, 4);
                label = new Label(5, 4, "录单日期：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(6, 4, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
//                label = new Label(7,4,"总数量：" ,wcfmt4);
//                wsheet.addCell(label);
//                label = new Label(8,4,objjson.getString("TOTAL_AMOUNT").replaceAll("&nbsp;", ""),wcfmt4);
//                wsheet.addCell(label);


                label = new Label(0, 5, "备注：", wcfmt4);
                wsheet.addCell(label);
                label = new Label(1, 5, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 7, 8, 7);


                label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                wsheet.addCell(label);
                wsheet.mergeCells(0, 9, 8, 9);

                label = new Label(0, 11, "序号");
                wsheet.addCell(label);
                label = new Label(1, 11, "选题名称");
                wsheet.addCell(label);
                label = new Label(2, 11, "印次");
                wsheet.addCell(label);
                label = new Label(3, 11, "金额");
                wsheet.addCell(label);

                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }

                for (int i = 0; i < overbase; i++) {
                    int index = t * maxnum + i;
                    try {


                        JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                        System.out.println(jsonObject.toString());

                        label = new Label(0, (i + 13), (i + 1) + "");
                        wsheet.addCell(label);
                        label = new Label(1, (i + 13), jsonObject.getString("XT_ID").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(2, (i + 13), jsonObject.getString("YINCI").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);
                        label = new Label(3, (i + 13), jsonObject.getString("NO_REAL_MONEY").replaceAll("&nbsp;", ""));
                        wsheet.addCell(label);

                        String bcsString = "";
                        try {
                            bcsString = jsonObject.getString("PACKNUM").replaceAll("&nbsp;", "");
                        } catch (Exception e) {
                            // TODO: handle exception
                        }
                        label = new Label(8, (i + 13), bcsString);
                        wsheet.addCell(label);
                    } catch (Exception e) {
                        System.out.println(e);
                        System.out.println(i);
                    }
                }


                wsheet.mergeCells(0, overbase + 13 + 1, 8, overbase + 13);

                label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 11, 8, overbase + 13 + 11);
                label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 13 + 13, 8, overbase + 13 + 13);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    //设置表头
                    wsheet.setColumnView(0, 10); // 设置列的宽度
                    wsheet.setColumnView(1, 16); // 设置列的宽度
                    wsheet.setColumnView(2, 31); // 设置列的宽度
                    wsheet.setColumnView(3, 8); // 设置列的宽度
                    wsheet.setColumnView(4, 12); // 设置列的宽度
                    wsheet.setColumnView(5, 12); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 10); // 设置列的宽度
                    wsheet.setColumnView(8, 11); // 设置列的宽度


                    wsheet.setRowView(12, 0);
                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 8, 0);

                    label = new Label(0, 2, "出版社：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 2, objjson.getString("PUB_ID").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 2, "账户号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 2, objjson.getString("CARD_NO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 2, 2, 2);
                    label = new Label(5, 2, "账户名：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 2, objjson.getString("ACCOUNT_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 2, "开户行：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 2, objjson.getString("BANK_NAME").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);


                    label = new Label(0, 3, "预付金额:", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 3, objjson.getString("PREPAID_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 3, "占用金额：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 3, objjson.getString("OCCUPANCY_AMOUNT").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 3, 4, 3);
                    label = new Label(5, 3, "已使用金额：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 3, objjson.getString("AMOUNT_USED").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(7, 3, "预付余额：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(8, 3, objjson.getString("PREPAID_BALANCE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);

                    label = new Label(0, 4, "单据号：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(1, 4, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(2, 4, "录单员：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(3, 4, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 4, 4, 4);
                    label = new Label(5, 4, "录单日期：", wcfmt4);
                    wsheet.addCell(label);
                    label = new Label(6, 4, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 6, 8, 6);

                    label = new Label(0, 5, "备注：", wcfmt5);
                    wsheet.addCell(label);
                    label = new Label(1, 5, objjson.getString("MEMO").replaceAll("&nbsp;", ""), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 7, 8, 7);

                    label = new Label(0, 9, "请仔细核对货物品种、数量、配书，如有货物与单据不符请及时与我公司联系。");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 9, 8, 9);

                    label = new Label(0, 11, "序号");
                    wsheet.addCell(label);
                    label = new Label(1, 11, "选题名称");
                    wsheet.addCell(label);
                    label = new Label(2, 11, "印次");
                    wsheet.addCell(label);
                    label = new Label(3, 11, "金额");
                    wsheet.addCell(label);


                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {


                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            System.out.println(jsonObject.toString());

                            label = new Label(0, (i + 13), (i + 1) + "");
                            wsheet.addCell(label);
                            label = new Label(1, (i + 13), jsonObject.getString("XT_NAME").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 13), jsonObject.getString("YINCI").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 13), jsonObject.getString("NO_REAL_MONEY").replaceAll("&nbsp;", ""));
                            wsheet.addCell(label);

                            String bcsString = "";
                            try {
                                bcsString = jsonObject.getString("PACKNUM").replaceAll("&nbsp;", "");
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                            label = new Label(8, (i + 13), bcsString);
                            wsheet.addCell(label);
                        } catch (Exception e) {
                            System.out.println(e);
                            System.out.println(i);
                        }
                    }
                    wsheet.mergeCells(0, overbase + 13 + 1, 8, overbase + 13);


                    label = new Label(0, overbase + 13 + 11, "请仔细核对货物品种、数量、金额，如有货物与单据明细不符，请及时与我公司人员联系！！！");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 11, 8, overbase + 13 + 11);
                    label = new Label(0, overbase + 13 + 13, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 13 + 13, 8, overbase + 13 + 13);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }

    /**
     * 出版社对账导出
     * <p/>
     * jxlfords_cw_press1
     * ds_cw_press1
     */
    @RequestMapping("jxlfords_cw_press1")
    @ResponseBody
    public String jxlfords_cw_press1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            if (sflag.equals("s")) {  //只是打印单录单
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                String zSql = sysPrint.getZsql();
                object = printService.gePrintDataBySql(zSql, pkVal);
            } else if (sflag.equals("m")) {  //打的表单是明细
                System.out.println(dsId + "--" + name);
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                if ("ds_fx_clients_jslist1".equals(dsId)) {     //销售对账
                } else {
                    System.out.println(dsId + "--" + name);
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    String mSql = sysPrint.getMsql();
                    List dateList = printService.getPrintMList(mSql, pkVal, config);
                    list2 = dateList;
                    //req.setAttribute("dataList",dateList);
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //			req.setAttribute("data",object);
            companyMap = printService.getCompanyInfo();

            //			req.setAttribute("Company", companyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
        System.out.println(objjson2.toString());
        try {
            String fileName = "杭州果麦文化传媒有限公司出版社对账单";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);

            //开头
            WritableFont wtf0 = new WritableFont(WritableFont.createFont("宋体"),

                    12, WritableFont.BOLD, false
                    , UnderlineStyle.NO_UNDERLINE, Colour.BLACK//yanshe
            );
            WritableCellFormat wcfmt1 = new WritableCellFormat(wtf0);
            wcfmt1.setAlignment(jxl.format.Alignment.CENTRE);


            //有边框
            WritableFont wtf4 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD, false);
            WritableCellFormat wcfmt4 = new WritableCellFormat(wtf4);
            wcfmt4.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
            wcfmt4.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);

            int ncout = list2.size();
            int maxnum = 50000; //一次最多写入量
            int times = (ncout + maxnum - 1) / maxnum;
            //大循环
            if (times == 0) {
                int t = 0;

                //新建一张表

                WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                //设置表头
                //设置宽度
                wsheet.setColumnView(0, 15); // 设置列的宽度
                wsheet.setColumnView(1, 15); // 设置列的宽度
                wsheet.setColumnView(2, 15); // 设置列的宽度
                wsheet.setColumnView(3, 15); // 设置列的宽度
                wsheet.setColumnView(4, 15); // 设置列的宽度
                wsheet.setColumnView(5, 15); // 设置列的宽度
                wsheet.setColumnView(6, 15); // 设置列的宽度
                wsheet.setColumnView(7, 15); // 设置列的宽度
                wsheet.setColumnView(8, 15); // 设置列的宽度
                wsheet.setColumnView(9, 15); // 设置列的宽度
                wsheet.setColumnView(10, 15); // 设置列的宽度
                wsheet.setColumnView(11, 15); // 设置列的宽度
                wsheet.setColumnView(12, 15); // 设置列的宽度
                //wsheet.setRowView(12, 0);

                Label label = new Label(0, 0, fileName, wcfmt1);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 0, 12, 0);

                label = new Label(0, 1, "出版社:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 1, 0, 1);
                label = new Label(1, 1, objjson.getString("PUB_ID"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 1, 2, 1);
                label = new Label(3, 1, "应付金额:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 1, 3, 1);
                label = new Label(4, 1, objjson.getString("REAL_MONEY"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 1, 4, 1);
                label = new Label(5, 1, "金额(不含税):", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 1, 5, 1);
                label = new Label(6, 1, objjson.getString("REAL_BHMONEY"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(6, 1, 6, 1);

                label = new Label(0, 2, "税金:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(0, 2, 0, 2);
                label = new Label(1, 2, objjson.getString("TAX_MONEY"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(1, 2, 1, 2);
                label = new Label(2, 2, "单据号:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(2, 2, 2, 2);
                label = new Label(3, 2, objjson.getString("DJ_CODE"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(3, 2, 3, 2);
                label = new Label(4, 2, "备注:", wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(4, 2, 4, 2);
                label = new Label(5, 2, objjson.getString("MEMO"), wcfmt4);
                wsheet.addCell(label);
                wsheet.mergeCells(5, 2, 6, 2);


                label = new Label(0, 5, "审核日期");
                wsheet.addCell(label);
                label = new Label(1, 5, "成本确认单据号");
                wsheet.addCell(label);
                label = new Label(2, 5, "成本类型");
                wsheet.addCell(label);
                label = new Label(3, 5, "图书名称");
                wsheet.addCell(label);
                label = new Label(4, 5, "印次");
                wsheet.addCell(label);
                label = new Label(5, 5, "开本");
                wsheet.addCell(label);
                label = new Label(6, 5, "定价");
                wsheet.addCell(label);
                label = new Label(7, 5, "印数");
                wsheet.addCell(label);
                label = new Label(8, 5, "入库数");
                wsheet.addCell(label);
                label = new Label(9, 5, "应付金额");
                wsheet.addCell(label);
                label = new Label(10, 5, "附加");
                wsheet.addCell(label);
                label = new Label(11, 5, "供应商");
                wsheet.addCell(label);


                int base = (t * maxnum);
                int overbase = (t + 1) * maxnum;
                if (overbase > list2.size()) {
                    overbase = list2.size() - base;
                } else {
                    overbase = maxnum;
                }


                label = new Label(0, overbase + 7, "技术支持：上海爱你特科技  www.ainit.cn");
                wsheet.addCell(label);
                wsheet.mergeCells(0, overbase + 7, 12, overbase + 7);
            } else {
                for (int t = 0; t < times; t++) {

                    //新建一张表

                    WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
                    wsheet.setColumnView(0, 15); // 设置列的宽度
                    wsheet.setColumnView(1, 15); // 设置列的宽度
                    wsheet.setColumnView(2, 15); // 设置列的宽度
                    wsheet.setColumnView(3, 15); // 设置列的宽度
                    wsheet.setColumnView(4, 15); // 设置列的宽度
                    wsheet.setColumnView(5, 15); // 设置列的宽度
                    wsheet.setColumnView(6, 15); // 设置列的宽度
                    wsheet.setColumnView(7, 15); // 设置列的宽度
                    wsheet.setColumnView(8, 15); // 设置列的宽度
                    wsheet.setColumnView(9, 15); // 设置列的宽度
                    wsheet.setColumnView(10, 15); // 设置列的宽度
                    wsheet.setColumnView(11, 15); // 设置列的宽度
                    wsheet.setColumnView(12, 15); // 设置列的宽度


                    Label label = new Label(0, 0, fileName, wcfmt1);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 0, 12, 0);

                    label = new Label(0, 1, "出版社:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 1, 0, 1);
                    label = new Label(1, 1, objjson.getString("PUB_ID"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 1, 2, 1);
                    label = new Label(3, 1, "应付金额:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 1, 3, 1);
                    label = new Label(4, 1, objjson.getString("REAL_MONEY"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 1, 4, 1);
                    label = new Label(5, 1, "金额(不含税):", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 1, 5, 1);
                    label = new Label(6, 1, objjson.getString("REAL_BHMONEY"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(6, 1, 6, 1);

                    label = new Label(0, 2, "税金:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, 2, 0, 2);
                    label = new Label(1, 2, objjson.getString("TAX_MONEY"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(1, 2, 1, 2);
                    label = new Label(2, 2, "单据号:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(2, 2, 2, 2);
                    label = new Label(3, 2, objjson.getString("DJ_CODE"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(3, 2, 3, 2);
                    label = new Label(4, 2, "备注:", wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(4, 2, 4, 2);
                    label = new Label(5, 2, objjson.getString("MEMO"), wcfmt4);
                    wsheet.addCell(label);
                    wsheet.mergeCells(5, 2, 6, 2);


                    label = new Label(0, 5, "审核日期");
                    wsheet.addCell(label);
                    label = new Label(1, 5, "成本确认单据号");
                    wsheet.addCell(label);
                    label = new Label(2, 5, "成本类型");
                    wsheet.addCell(label);
                    label = new Label(3, 5, "图书名称");
                    wsheet.addCell(label);
                    label = new Label(4, 5, "印次");
                    wsheet.addCell(label);
                    label = new Label(5, 5, "开本");
                    wsheet.addCell(label);
                    label = new Label(6, 5, "定价");
                    wsheet.addCell(label);
                    label = new Label(7, 5, "印数");
                    wsheet.addCell(label);
                    label = new Label(8, 5, "入库数");
                    wsheet.addCell(label);
                    label = new Label(9, 5, "应付金额");
                    wsheet.addCell(label);
                    label = new Label(10, 5, "附加");
                    wsheet.addCell(label);
                    label = new Label(11, 5, "供应商");
                    wsheet.addCell(label);

                    int base = (t * maxnum);
                    int overbase = (t + 1) * maxnum;
                    if (overbase > list2.size()) {
                        overbase = list2.size() - base;
                    } else {
                        overbase = maxnum;
                    }

                    for (int i = 0; i < overbase; i++) {
                        int index = t * maxnum + i;
                        try {
                            JSONObject jsonObject = JSONObject.fromObject(list2.get(index));
                            label = new Label(0, (i + 6), jsonObject.getString("VERIFY_DATE"));
                            wsheet.addCell(label);
                            label = new Label(1, (i + 6), jsonObject.getString("DJ_CODE"));
                            wsheet.addCell(label);
                            label = new Label(2, (i + 6), jsonObject.getString("DJ_TYPE"));
                            wsheet.addCell(label);
                            label = new Label(3, (i + 6), jsonObject.getString("XT_ID"));
                            wsheet.addCell(label);
                            label = new Label(4, (i + 6), jsonObject.getString("YINCI"));
                            wsheet.addCell(label);
                            label = new Label(5, (i + 6), jsonObject.getString("KAIBEN"));
                            wsheet.addCell(label);
                            label = new Label(6, (i + 6), jsonObject.getString("H_PRICE"));
                            wsheet.addCell(label);
                            label = new Label(7, (i + 6), jsonObject.getString("YINSHU"));
                            wsheet.addCell(label);
                            label = new Label(8, (i + 6), jsonObject.getString("RUKUSHU"));
                            wsheet.addCell(label);
                            label = new Label(9, (i + 6), jsonObject.getString("REAL_MONEY"));
                            wsheet.addCell(label);
                            label = new Label(10, (i + 6), jsonObject.getString("MONEY"));
                            wsheet.addCell(label);
                            label = new Label(11, (i + 6), jsonObject.getString("JIAFANG"));
                            wsheet.addCell(label);
                        } catch (Exception e) {

                        }
                    }

                    label = new Label(0, overbase + 9, "技术支持：上海爱你特科技  www.ainit.cn");
                    wsheet.addCell(label);
                    wsheet.mergeCells(0, overbase + 9, 12, overbase + 9);
                }
            }

            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }



    /**
     * 作者对账单导出
     *
     *
     */
    @RequestMapping("jxlfords_zc_authorcheck1")
    @ResponseBody
    public String jxlforzc_authorcheck1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_zc_authorcheck1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);
                    list2 = dateList;

//                    String VENDOR_ID = JSONObject.fromObject(object).getString("VENDOR_ID").replaceAll("&nbsp;", "");
//                    String MMSQL = "SELECT (TO_CHAR(VV.IS_STOKETIME, 'yyyy-mm-dd')) IS_STOKETIME, VV.DJ_CODE, (select STATUS_NAME from (SELECT 'IN' STATUS_ID, '纸张入库单' STATUS_NAME from dual UNION ALL SELECT 'TH' STATUS_ID, '纸张退货单' STATUS_NAME from dual UNION ALL SELECT 'RK' STATUS_ID, '纸张其他入库单' STATUS_NAME from dual) aa where aa.STATUS_ID = VV.DJ_TYPE) DJ_TYPE, VV.CL_HETONGHAO, (select b.cl_name from bs_material b where b.cl_id = VV.CL_ID) CL_NAME, VV.CL_STANDARD, VV.CL_PRICE, (select name from bs_comparison where comparison_id = 'cljlUnit' and codeId = VV.CL_UNIT) CL_UNIT, VV.TOTAL_AMOUNT, VV.REAL_MONEY, VV.TAX_RATE, VV.TAX_MONEY, VV.MX_BHMONEYSUM FROM VV_CW_ZCDZ VV left join bs_man on bs_man.man_id=vv.VENDOR_ID WHERE VV.I_INFO NOT IN (SELECT CMI.I_INFO FROM cw_clreconcid_item CMI LEFT JOIN CW_CLRECONCID CM ON CMI.CL_ID = CM.CL_ID WHERE cm.is_destroy = '0') AND bs_man.m_name='" + VENDOR_ID + "'";
//                    list3 = printService.getPrintMMList(MMSQL);

                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }
            //2.4 最后将主表数据设置上

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        JSONObject objjson2 = JSONObject.fromObject(companyMap);
        System.out.println(objjson.toString());
//

        try {
//			String fileName=objjson2.getString("COM_FLLNAME").replaceAll("&nbsp;", "")+"纸厂对账";
            String fileName = "作者对账";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);


            //大循环

            int t = 0;

            //新建一张表

            WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
            //设置表头

            Label label = new Label(0, 0, fileName);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "付款对象：");
            wsheet.addCell(label);
            label = new Label(1, 1, objjson.getString("PAY_PARTY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 1, 7, 1);

            label = new Label(5, 1, "选题名称：");
            wsheet.addCell(label);
            label = new Label(6, 1, objjson.getString("TOPIC_SELECTED").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 1, 7, 1);

            label = new Label(8, 1, "作者：");
            wsheet.addCell(label);
            label = new Label(9, 1, objjson.getString("AUTHOR").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 1, 7, 1);

            label = new Label(10, 1, "定价：");
            wsheet.addCell(label);
            label = new Label(11, 1, objjson.getString("PRICE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 1, 7, 1);



            label = new Label(0, 2, "结算依据：");
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("BASIS_ACCOUNT").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 7, 1);

            label = new Label(5, 2, "发票类型：");
            wsheet.addCell(label);
            label = new Label(6, 2, objjson.getString("TYPE_TICKET").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 2, 7, 1);

            label = new Label(8, 2, "税率：");
            wsheet.addCell(label);
            label = new Label(9, 2, objjson.getString("TAX_RATE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 2, 7, 1);

            label = new Label(10, 2, "是否促销：");
            wsheet.addCell(label);
            label = new Label(11, 2, objjson.getString("ROYALTY_SALE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 2, 7, 1);







            label = new Label(0, 3, "版税参数：");
            wsheet.addCell(label);
            label = new Label(1, 3, objjson.getString("PARAMETER_ROYALTY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 3, 7, 1);

            label = new Label(8, 3, "本期净发货数:：");
            wsheet.addCell(label);
            label = new Label(9, 3, objjson.getString("NUMBER_DELIVERY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 3, 7, 1);

            label = new Label(10, 3, "历史净发货数：");
            wsheet.addCell(label);
            label = new Label(11, 3, objjson.getString("NUMBER_TOTAL_DELIVERY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 3, 7, 1);



            label = new Label(0, 4, "应付：");
            wsheet.addCell(label);
            label = new Label(1, 4, objjson.getString("PAY_SHOULD").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 4, 7, 1);

            label = new Label(5, 4, "实付：");
            wsheet.addCell(label);
            label = new Label(6, 4, objjson.getString("PAY_REAL").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 4, 7, 1);

            label = new Label(8, 4, "本期印数：");
            wsheet.addCell(label);
            label = new Label(9, 4, objjson.getString("NUMBER_PRINT").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 4, 7, 1);

            label = new Label(10, 4, "历史总印数:：");
            wsheet.addCell(label);
            label = new Label(11, 4, objjson.getString("NUMBER_TOTAL_PRINT").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 4, 7, 1);


            label = new Label(0, 5, "计算公式：");
            wsheet.addCell(label);
            label = new Label(1, 5, objjson.getString("FORMULAS_CALCULATE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 5, 7, 1);

            label = new Label(8, 5, "促销数：");
            wsheet.addCell(label);
            label = new Label(9, 5, objjson.getString("NUMBER_SALE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 5, 7, 1);

            label = new Label(10, 5, "预付余额：");
            wsheet.addCell(label);
            label = new Label(11, 5, objjson.getString("BALANCE_PREPAY").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 5, 7, 1);

            label = new Label(0, 6, "备注：");
            wsheet.addCell(label);
            label = new Label(1, 6, objjson.getString("MEMO").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 6, 7, 1);



            label = new Label(8, 6, "单据号：");
            wsheet.addCell(label);
            label = new Label(9, 6, objjson.getString("DJ_CODE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 6, 7, 1);


            label = new Label(10, 6, "导出日期：");
            wsheet.addCell(label);
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String daString = "";
            daString = simpleDateFormat.format(date);
            label = new Label(11, 6, daString);
            wsheet.addCell(label);

            label = new Label(0, 8, "序号");
            wsheet.addCell(label);
            label = new Label(1, 8, "月份");
            wsheet.addCell(label);
            label = new Label(2, 8, "单据类型");
            wsheet.addCell(label);
            label = new Label(3, 8, "选题名称");
            wsheet.addCell(label);
            label = new Label(4, 8, "书号");
            wsheet.addCell(label);
            label = new Label(5, 8, "数量");
            wsheet.addCell(label);
            label = new Label(6, 8, "印次");
            wsheet.addCell(label);


            if (list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(list2.get(i));
                    label = new Label(0, 9 + i, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 9 + i, objjsonzn.getString("ZZDZ_MONTH").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 9 + i, objjsonzn.getString("DJ_TYPE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 9 + i, objjsonzn.getString("TOPIC_SELECTED").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 9 + i, objjsonzn.getString("ZZDZ_ISBN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 9 + i, objjsonzn.getString("AMOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(6, 9 + i, objjsonzn.getString("NUMBER_PRINT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);

                }
            }


            label = new Label(0, 9 + list2.size() + 5  + 12, "技术支持:上海爱你特科技www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 9 + list2.size() + 5 + 12, 9, 9 + list2.size() + 5  + 12);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }





    /**
     *每月实效上报（按月）
     *
     *
     */
    @RequestMapping("jxlfords_fx_MonthSX1")
    @ResponseBody
    public String jxlfords_fx_MonthSX1(HttpServletRequest req, HttpServletResponse response, HttpSession session, String pkVal, String dsId, String name, String config, String sflag) throws ParseException {
        String rmark = "导出成功";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        SysPrint sysPrint = null;
        Object object = null;
        Map<String, Object> companyMap = new HashMap<String, Object>();
        String[] itme = name.split("_");
        if (itme.length > 1) {
            name = itme[1];
        }
        try {
            //2.1 单录单打印
            if (sflag.equals("s")) {  //只是打印单录单
            } else if (sflag.equals("m")) {  //打的表单是明细
                //2.2 主明细单打印
                sysPrint = printService.getPrintObj(dsId, name);   //根据用户选择的模板找到对应的模板对象
                //2.2.1 如果是对账结算单打印
                if ("ds_fx_MonthSX1".equals(dsId)) {
                    List<Map<String, Object>> list_ = new ArrayList<Map<String, Object>>();
                    String zSql = sysPrint.getZsql();
                    object = printService.gePrintDataBySql(zSql, pkVal);
                    System.out.println("PrintController #L.257#  明细主表的sql:" + zSql);
                    String mSql = sysPrint.getMsql();

                    List<Map<String, Object>> dateList = printService.getPrintMList(mSql, pkVal, config);
                    System.out.println("PrintController #L.260# 明细子表的sql:" + mSql);
                    list2 = dateList;



                } else {
                }
            } else if (sflag.equals("l")) {  //打的查询界面
            }

            //2.5 设置公司信息
            companyMap = printService.getCompanyInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject objjson = JSONObject.fromObject(object);
        System.out.println(objjson.toString());


        try {
            String fileName = "每月客户实效上报（按月）";
            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("GBK"), "iso-8859-1") + ".xls" + "\"");
            OutputStream os = response.getOutputStream();
            WritableWorkbook wwb = Workbook.createWorkbook(os);


            //大循
            int t = 0;
            //新建一张表
            WritableSheet wsheet = wwb.createSheet("members_" + (t + 1), t);
            //设置表头

            Label label = new Label(0, 0, fileName);
            wsheet.addCell(label);
            wsheet.mergeCells(0, 0, 7, 0);

            label = new Label(0, 1, "客户名称：");
            wsheet.addCell(label);
            label = new Label(1, 1, objjson.getString("CLIENT_ID").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 1, 7, 1);

            label = new Label(5, 1, "片区经理：");
            wsheet.addCell(label);
            label = new Label(6, 1, objjson.getString("O_ID_LASTGR").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 1, 7, 1);

            label = new Label(8, 1, "录单员：");
            wsheet.addCell(label);
            label = new Label(9, 1, objjson.getString("INPUT_MAN").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(9, 1, 7, 1);

            label = new Label(10, 1, "录单日期：");
            wsheet.addCell(label);
            label = new Label(11, 1, objjson.getString("INPUT_DATE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(11, 1, 7, 1);



            label = new Label(0, 2, "导入日期：");
            wsheet.addCell(label);
            label = new Label(1, 2, objjson.getString("IMPORT_DATE").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(1, 2, 7, 1);

            label = new Label(5, 2, "备注：");
            wsheet.addCell(label);
            label = new Label(6, 2, objjson.getString("MEMO").replaceAll("&nbsp;", ""));
            wsheet.addCell(label);
            wsheet.mergeCells(6, 2, 7, 1);



            label = new Label(0, 5, "序号");
            wsheet.addCell(label);
            label = new Label(1, 5, "书号");
            wsheet.addCell(label);
            label = new Label(2, 5, "商品名称");
            wsheet.addCell(label);
            label = new Label(3, 5, "定价");
            wsheet.addCell(label);
            label = new Label(4, 5, "销售数量");
            wsheet.addCell(label);
            label = new Label(5, 5, "历史平均发货折扣");
            wsheet.addCell(label);
            label = new Label(6, 5, "销售单价");
            wsheet.addCell(label);
            label = new Label(7, 5, "销售收入");
            wsheet.addCell(label);
            label = new Label(8, 5, "客户库存");
            wsheet.addCell(label);


            if (list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    JSONObject objjsonzn = JSONObject.fromObject(list2.get(i));
                    label = new Label(0, 6 + i, (i + 1) + "");
                    wsheet.addCell(label);
                    label = new Label(1, 6 + i, objjsonzn.getString("H_ISBN").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(2, 6 + i, objjsonzn.getString("H_ID").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(3, 6 + i, objjsonzn.getString("H_PRICE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(4, 6 + i, objjsonzn.getString("H_AMOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(5, 6 + i, objjsonzn.getString("H_DISCOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(6, 6 + i, objjsonzn.getString("XS_PRICE").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(7, 6 + i, objjsonzn.getString("XS_MONEY").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);
                    label = new Label(8, 6 + i, objjsonzn.getString("AMOUNT").replaceAll("&nbsp;", ""));
                    wsheet.addCell(label);

                }
            }


            label = new Label(0, 6 + list2.size() + 5  + 12, "技术支持:上海爱你特科技www.ainit.cn");
            wsheet.addCell(label);
            wsheet.mergeCells(0, 6 + list2.size() + 5 + 12, 6, 6 + list2.size() + 5  + 12);


            wwb.write();
            wwb.close();
            os.flush();
        } catch (Exception e) {
            System.out.println(e);
            System.out.println("生成信息表(Excel格式)时出错：");
            rmark = "导出失败";
            e.printStackTrace();
        }
        return rmark;
    }
}
































































